case class Simple(x: String)
and I wanna change the field name from x to y when serialize it into json,so I do:implicit val formats = DefaultFormats +
FieldSerializer[Simple](renameTo("x","y"),renameFrom("y", "x"))
I thought the output ofSerialization.write(Simple("test"))
would be : {"y":"test"}
however it is {"y":"test","x":"test"}
is this a expected behavior? what should I do if I want the result be :{"y":"test"} ?
--
--
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
import net.liftweb.json._import FieldSerializer._object TestApp extends App {case class Simple(x: String)
implicit val formats = DefaultFormats +
FieldSerializer2[Simple](renameTo("x", "y"), renameFrom("y", "x"))val json = Extraction.decompose(Simple("test"))println(json) // JObject(List(JField(y,JString(test))))val simple = json.extract[Simple]println(simple) // Simple(test)}P.S. 中国人吗?多交流。