lift-json

Why do I get “$outer” In my json string when using lift-json?

北慕城南 提交于 2020-02-05 04:32:29
问题 Let me preface by saying I am new to working with json and serialization and such. I am trying to create some json from some case classes. Here is my code from a scala worksheet I'm playing with: import net.liftweb.json.DefaultFormats import net.liftweb.json.Serialization.write implicit val formats = DefaultFormats // DBObjectTypes is an enumeration not shown in this snippet. def update(dbObject: DBObjectTypes, updatePair: Map[String, Any]): Unit = { case class Query(objectType: String, id:

Using Lift-Json with Case Classes

倾然丶 夕夏残阳落幕 提交于 2020-01-16 18:05:51
问题 I can't seem to write proper case classes for this particular Json payload. I believe it has something to do with the first index in the array, which doesn't have a key string. Any ideas on how to remedy this? For reference, I am using Scala 2.10.4, Akka 2.3.2, Spray 1.3.1 and Lift-Json 2.6. The Json I am attempting to extract is from Mailgun's Events API. Edit: the core question is how do I extract to a case class with no key in the Json? My code follows: import net.liftweb.json._ case class

Get json data in d3 from lift snippet

北城余情 提交于 2019-12-22 11:34:13
问题 I am currently implementing a graph using d3 and a json object for data. A working example of such a graph can be found here: http://bl.ocks.org/950642. If you know d3 you can certainly directly jump to the My Problem part. Quick overview of code So, basically in my template I have the minimum code necessary: <div id="main" class="lift:surround?with=default;at=content"> <div class="lift:GraphVisual.showGraph"></div> </div> Then in my snippet ( GraphVisual.scala ) I have the following: def

How to fill case class from json with partial data?

本秂侑毒 提交于 2019-12-22 04:58:41
问题 import net.liftweb.json._ import net.liftweb.json.JsonParser._ object test02 extends App { implicit val formats = DefaultFormats case class User( id: Int = 0, name: String = "John Doe", gender: String = "M") val s1=""" {"id":1,"name":"Bill","gender":"M"} """ var r1=Serialization.read[User](s1) println(r1) val s2=""" {"id":1} """ var r2=Serialization.read[User](s2) println(r2) } Second Serialization.read causes exception: net.liftweb.json.MappingException: No usable value for name. How could I

spark-core 1.6.1 & lift-json 2.6.3 java.lang.NoClassDefFoundError

牧云@^-^@ 提交于 2019-12-12 09:19:42
问题 I have a Spark application which has a sbt file just like below. It works on my local machine. But when I submit it to EMR running Spark 1.6.1, an error occured like below: java.lang.NoClassDefFoundError: net/liftweb/json/JsonAST$JValue I am using "sbt-package" to get jar Build.sbt: organization := "com.foo" name := "FooReport" version := "1.0" scalaVersion := "2.10.6" libraryDependencies ++= Seq( "org.apache.spark" %% "spark-core" % "1.6.1" ,"net.liftweb" % "lift-json_2.10" % "2.6.3" ,"joda

How to Manipulate JSON AST in Scala

霸气de小男生 提交于 2019-12-06 21:52:22
问题 I am experimenting with the json4s library (based on lift-json). One of the things I would like to do is to parse a JSON string into an AST, and then manipulate it. For example, I would like to upsert a field (insert the field into the AST if it does not exist, or update its value if it does). I have not been able to find how to do it in the documentation. Experimenting with the available methods, I have come up with the following, which works, but feels clumsy. import org.json4s._ import org

Get json data in d3 from lift snippet

依然范特西╮ 提交于 2019-12-06 10:50:00
I am currently implementing a graph using d3 and a json object for data. A working example of such a graph can be found here: http://bl.ocks.org/950642 . If you know d3 you can certainly directly jump to the My Problem part. Quick overview of code So, basically in my template I have the minimum code necessary: <div id="main" class="lift:surround?with=default;at=content"> <div class="lift:GraphVisual.showGraph"></div> </div> Then in my snippet ( GraphVisual.scala ) I have the following: def showGraph = { <h3>Bachelor 5/6 - Communication Systems</h3> ++ <div id="graph-container" width="500px"

Lift-json extract json with 'type' field into a case class

风流意气都作罢 提交于 2019-12-05 15:11:55
问题 I am trying to extract JSON into a case class using lift-json. Here is my case class: case class Person(name: String, age: Int) Here is the json { "name": "Some Name", "age": 24, type: "Student" } How can I extract the type field into an instance Person ? json.extract[Person] 回答1: Backticks allow you to use reserved names. case class Person(name:String, age:Int, `type`:String) 来源: https://stackoverflow.com/questions/7462493/lift-json-extract-json-with-type-field-into-a-case-class

How to Manipulate JSON AST in Scala

若如初见. 提交于 2019-12-05 03:23:20
I am experimenting with the json4s library (based on lift-json). One of the things I would like to do is to parse a JSON string into an AST, and then manipulate it. For example, I would like to upsert a field (insert the field into the AST if it does not exist, or update its value if it does). I have not been able to find how to do it in the documentation. Experimenting with the available methods, I have come up with the following, which works, but feels clumsy. import org.json4s._ import org.json4s.JsonDSL._ import org.json4s.native.JsonMethods._ object TestJson { implicit val formats =

Serialize a map that doesn't have a string as a key with lift-json

自闭症网瘾萝莉.ら 提交于 2019-12-05 00:05:08
问题 It seems like lift-json is limited to maps that have Strings as keys. What is the best way to bypass this limitation ? 回答1: Define your own Serializer[Map[Any, Any]] . import net.liftweb.json._ import ext._ object MapSerializer extends Serializer[Map[Any, Any]] { def serialize(implicit format: Formats): PartialFunction[Any, JValue] = { case m: Map[_, _] => JObject(m.map({ case (k, v) => JField( k match { case ks: String => ks case ks: Symbol => ks.name case ks: Any => ks.toString },