json4s

how to represent nested JSON object in a case class using Json4s?

梦想的初衷 提交于 2020-01-06 01:27:12
问题 Given an example JSON object with a nested object who's properties are unkown: { "Key":"01234", "eventProperties":{ "unknownProperty1":"value", "unknownProperty2":"value", "unknownProperty3":"value" }, } I have tried to use json4s' extract function with the following case class (In Scala): case class nestedClass(Key:String, eventProperties:Map[(String,Any)]) Which results in the following error: org.json4s.package$MappingException: Can't find constructor for nestedClass Is it possible to do

Can't find ScalaSig for class - json4s with scala + proguard for an android app

自作多情 提交于 2020-01-05 18:01:38
问题 I have a very simple case class (Baz) that I want to serialise to JSON using json4s-native. I cannot seem to get this to work at all, when using Proguard to make an android apk. When serialising, the following exception occurs: java.lang.RuntimeException: java.lang.reflect.InvocationTargetException at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:555) at dalvik.system.NativeStart.main(Native Method) Caused by: java.lang.reflect.InvocationTargetException at java.lang.reflect.Method

Json4s support for case class with trait mixin

北慕城南 提交于 2020-01-04 01:29:27
问题 I am trying to serialize scala case class using json4s with jackson support. But for scenarios where i am trying to mixin traits, it fails to serialize the class. Below is a code example. trait ISearchKey { var id:String = "" } When i execute below code i get empty curly brackets, no value serialized, but if i remove trait mixin then CrystalFieldInfo value gets serialized properly val fld = new CrystalFieldInfo("Field1") with ISearchKey fld.id = "Id1" implicit val formats = Serialization

Is there an out of the box (de)serializer for UUID in json4s?

时光毁灭记忆、已成空白 提交于 2019-12-30 08:15:08
问题 I'm having a problem very similar to what's described here: Combining type and field serializers case class(id: Option[UUID], otherValue:String, … ) The answer to the related question would allow me to write my own format, but I'm curious if there is already a format for UUID hiding somewhere in json4s. I'd guessed that the right import would solve this issue for UUID, and I was a bit surprised not to find anything. Did I miss it, or is it not there yet? 回答1: Since my pull request was merged,

Having trouble with implicit conversion in scala

限于喜欢 提交于 2019-12-25 03:22:42
问题 Having this code case class Workspace(ident: Long, name: String) case class Project(ident: Long, name: String) implicit def workspaceJSON: JSONR[Workspace] = new JSONR[Workspace] { def read(json: JValue) = Workspace.applyJSON(field[Long]("id"), field[String]("name"))(json) } implicit def projectJSON: JSONR[Project] = new JSONR[Project] { def read(json: JValue) = Project.applyJSON(field[Long]("id"), field[String]("name"))(json) } def parseEnt[T: JSONR](json: JValue): Either[String, T] =

Accessing attributes in objects Scala

匆匆过客 提交于 2019-12-25 01:45:45
问题 An example of the sort of objects I need to grab from my json can be found in the following example(src): { "test": { "attra": "2017-10-12T11:17:52.971Z", "attrb": "2017-10-12T11:20:58.374Z" }, "dummyCheck": false, "type": "object", "ruleOne": { "default": 2557 }, "ruleTwo": { "default": 2557 } } From the example above I want to access the default value under "ruleOne". I've tried messing about with several different things below but I seem to be struggling. I can grab values like "dummyCheck

How to deserialize a scala tree with JSON4S

跟風遠走 提交于 2019-12-25 00:23:10
问题 Serialization works fine but I have nothing for deserialization. I found interesting solution for abstract class here How to serialize sealed abstract class with Json4s in Scala? but it doesn't deal with trees. This the code of my test with a standard JSON4S : import org.json4s._ import org.json4s.native.JsonMethods._ import org.json4s.native.Serialization.{ read, write } import org.json4s.native.Serialization abstract class Tree case class Node(nameN: String, trees: List[Tree]) extends Tree

(Un)marshall JSON with named root for Ember Data using Scala case class on Spray

早过忘川 提交于 2019-12-23 05:44:11
问题 I am writing a RESTful interface and I would like to marshall and unmarshall JSON ready for Ember Data. The wrinkle is that Ember Data wants the entity name and the two libraries I've tried, spray-json and json4s, don't appear to do this easily. Desired Ember Data format { "coursePhoto": { "photoId": 1 } } Current default format: {"photoId":15} This should come from a case class: case class CoursePhoto(photoId: Long) I did get it running with the following custom code: object

How can I convert between play.api.libs.json.JsValue and or.json4s.JValue in Scala

只谈情不闲聊 提交于 2019-12-22 10:05:09
问题 I'm using Play Framework to build an API, but need to perform some validation and transformation operations with a library that only speaks Json4s. So far, the only thing I've been able to get to work is converting to a string and parsing with the target library: import org.json4s._ import org.json4s.jackson.JsonMethods._ import play.api.libs.json._ val playJson: JsValue = Json.parse(compact(render(json4sJson))) val json4sJson: JValue = parse(Json.stringify(playJson)) But that's obviously

How do you create Json object with values of different types?

我怕爱的太早我们不能终老 提交于 2019-12-22 05:54:51
问题 How do you create Json object with values of different types ? I'm using spray-json Here is the code val images : List[JsObject] = fetchImageUrls(url).map((url: String) => { JsObject(List( "link_path" -> JsString(url), "display_name" -> JsString("image"), "size" -> JsString(""), "modified" -> JsString(""), "thumbnail" -> JsString(url), "filename" -> JsString("image"), "is_dir" -> JsBoolean(x = false), "thumb_exists" -> JsBoolean(x = true)) ) }) val jsonAst: JsObject = JsObject(List( "client"