I’m using renderJSON(Object) to return some objects as JSON values, and it’s working fine except for one field. Is there an easy way to add in that one field without having to manually create the whole json template?
I’m using renderJSON(Object) to return some objects as JSON values, and it’s working fine
Share
Play uses GSON to build the JSON string. If your one field is a specific object type, then you can easily do this by providing a customised serialisation for that type. See the documentation here
http://sites.google.com/site/gson/gson-user-guide#TOC-Custom-Serialization-and-Deserializ
However, if it is an Integer class for example, that you want to work in one way for one, and another way for another, then you may have a little more difficulty.
Example