使用多个FieldSerializer的正确语法是什么?我正在尝试重命名3个字段,只有当我用DefaultFormats
连接其中一个字段时它才有效val currg = FieldSerializer[Currency](renameTo("gameCurr", "gameCurr"), renameFrom("currg", "gameCurr"))
val curre = FieldSerializer[Currency](renameTo("currency", "currency"), renameFrom("curre", "currency"))
val lprice = FieldSerializer[Currency](renameTo("price", "price"), renameFrom("lprice", "price"))
implicit val formats = org.json4s.DefaultFormats + lprice //+ curre + currg
如果我只使用一个FieldSerializer,它就像魅力一样
implicit val formats = org.json4s.DefaultFormats + lprice
答案 0 :(得分:2)
您可以使用FieldSerializer
重命名单个orElse
中的多个字段:
val rename_currency_fields = FieldSerializer[Currency](
renameTo("foo", "bar") orElse renameTo("baz", "qux")
renameFrom("bar", "foo") orElse renameFrom("qux", "baz")
)
implicit val formats = org.json4s.DefaultFormats + rename_currency_fields