lift json / json4s

44 views
Skip to first unread message

Georg Heiler

unread,
Dec 25, 2016, 4:13:47 AM12/25/16
to Lift
Hi,

What is wrong with my JSON serialization getting started with lift's JSON library (json4s)

import org.json4s.JsonDSL._
import org.json4s.jackson.JsonMethods._
import org.json4s.{DefaultFormats, JObject}

case class CountryKPI(country_id: String, country_id3: String,
                      country_value: String, indicator_id: String,
                      indicator_value: String, value: Double)

val mycc = CountryKPI("first", "FFF", "fff", "XXX", "xxx", 4.0)

implicit val format = DefaultFormats
val extraMetadata: JObject = ("foo" -> 1.0) ~
  ("countryKPIs" -> Array[CountryKPI](mycc)) ~
  ("holidaysAT" -> Array[LocalDate](LocalDate.now))

compact(render(extraMetadata))

Why doesn' t my code compile?

Strangely, implicit val formats = org.json4s.DefaultFormats ++ org.json4s.ext.JodaTimeSerializers.all
 doesn't seem to help

kind regards,
Georg

Diego Medina

unread,
Dec 25, 2016, 4:23:36 AM12/25/16
to Lift
Hi Georg,

I know that json4s says it's the same a lift-json, but changes are that at the very least, there are small changes, could you post a running example https://app.assembla.com/wiki/show/liftweb/Posting_example_code using lift-json ? that would helps us focus on getting your code working, vs updating your example to match lift-json and then figure out why your code isn't working.

You could clone this repo


the lift_json project in there has a ready to run lift-json test, you could update that code with your example (because running lift-json on the sbt console doesn't always work as expected)

Thanks

Diego



--
--
Lift, the simply functional web framework: http://liftweb.net
Code: http://github.com/lift
Discussion: http://groups.google.com/group/liftweb
Stuck? Help us help you: https://www.assembla.com/wiki/show/liftweb/Posting_example_code

---
You received this message because you are subscribed to the Google Groups "Lift" group.
To unsubscribe from this group and stop receiving emails from it, send an email to liftweb+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Diego Medina
Lift/Scala Consultant
di...@fmpwizard.com
https://blog.fmpwizard.com/

Matt Farmer

unread,
Dec 25, 2016, 10:57:13 AM12/25/16
to lif...@googlegroups.com
Hi there,

Mobile right now so this will be brief, but I wanted to add to Diego's response. Json4s has actually made pretty major changes to lift-json. The AST to class deserialization pipeline was entirely rewritten it seems. It actually breaks the ability to deserialize polymorphic types with type hints. 

I recommend switching to using lift-json - at least until that issue is fixed. 


Matt Farmer Blog | Twitter
GPG: CD57 2E26 F60C 0A61 E6D8  FC72 4493 8917 D667 4D07
To unsubscribe from this group and stop receiving emails from it, send an email to liftweb+u...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages