I’m trying to html-escape all strings in my objects when serializing them with Lift’s json library. I thought I could do this by passing an escape (partial) function to the objects’ FieldSerializer, but this seems to add fields to the json-object – not replace them. You can see what I mean by running the following simple example and note that it outputs
{"y":"test","x":"test"} while I wanted {"y":"test"}:
import net.liftweb.json.Serialization
import net.liftweb.json.FieldSerializer
import net.liftweb.json.FieldSerializer._
import net.liftweb.json.DefaultFormats
case class Simple(x: String)
implicit val formats = DefaultFormats +
FieldSerializer[Simple](renameTo("x","y"),renameFrom("y", "x"))
Serialization.write(Simple("test"))
Is there a way I can tell FieldSerializer to replace the field matched by my partial function?
Try CoustomeSerializer:
ps.I asked this on lift’s google group,and got this answer,checkout https://groups.google.com/d/msg/liftweb/ShRrGNrsu6Y/sNw4JGdSU6sJ