Scala 2.10 + Json serialization and deserialization

后端 未结 5 476
生来不讨喜
生来不讨喜 2020-12-04 14:28

Scala 2.10 seems to have broken some of the old libraries (at least for the time being) like Jerkson and lift-json.

The target usability is as follows:

<         


        
5条回答
  •  天涯浪人
    2020-12-04 15:08

    So, based on the absence of an error message and the incorrect sample code, I'm suspecting this is more of an issue of just not understanding how the lift-json extraction works. If I've misunderstood, do comment and let me know. So, if I'm right then here's what you need.

    To serialize:

    import net.liftweb.json._
      import Extraction._
    
    implicit val formats = DefaultFormats
    
    case class Person(...)
    val person = Person(...)
    val personJson = decompose(person) // Results in a JValue
    

    Then to reverse the process you'd do something like:

    // Person Json is a JValue here.
    personJson.extract[Person]
    

    If that's not the part you're having trouble with, then do let me know and I can try to revise my answer to be more helpful.

提交回复
热议问题