我试图在序列化case class
. 看起来正确的方法是CustomKeySerializer
从org.json4s
包中定义 a 并按照我的意愿重新格式化键。但是,虽然我能够让 aCustomSerializer
工作,但CustomKeySerializer
在序列化案例类(具有未知类型的嵌套案例类)时,我无法真正使用 a。我的代码如下所示:
case object PascalCaseSerializer extends CustomKeySerializer[String](format => (
{ case _ => "this is the deserializer and I don't need it" },
{ case _ => "this does nothing" }
))
implicit val formats: Formats = DefaultFormats + PascalCaseSerializer
case class Foo(thingId: Int, eventData: Any)
case class Bar(numThings: Int)
val event = Foo(1, Bar(2))
val payloadJson = write(event) // """{"thingId":1,"eventData":{"numThings":2}}"""
我在这里想念什么?