使用lift-json序列化和反序列化案例类

Jer*_*emy 8 serialization json scala lift

我正在尝试使用lift-json进行基本序列化/水合作用,但没有成功.从包装自述文件中可以看出,这应该可行.救命?

我正在使用Scala 2.8.0和Lift 2.2为sbt交叉构建2.8("net.liftweb"%%"lift-json"%"2.2").

import net.liftweb.json._
import net.liftweb.json.Serialization.{read, write}

implicit val formats = Serialization.formats(NoTypeHints)

case class Route(title: String)

val rt = new Route("x277a1")

val ser = write(rt)
// ser: String = {} ... 

val deser = read[Route]("""{"title":"Some Title"}""")
// net.liftweb.json.MappingException: Parsed JSON values do not match with class constructor
Run Code Online (Sandbox Code Playgroud)

Jon*_*oni 10

Lift JSON的序列化不适用于REPL中定义的case类(paranamer无法找到字节码来读取类型元数据).使用scalac编译路由,然后上面的示例工作.