I have a Java class like this and want to convert to JSON using Jackson. Thanks for your help.
Java Class
public class myClass { String Id; Map<String, Object> optionalData = new LinkedHashMap<String, Object>(); }
How to serialization it to JSON using Jackson ObjectMapper ?
For example, suppose the optionalData
is a Map saving two entries <"type", "book">
and <"year", "2014">
I want the output to be as follow. Please note that the key/value of optionalData could be changed on the fly (so, I cannot create a "static" Java object for this without using Map)
[
{
id: "book-id1",
type: "book",
year: "2014"
},
{
id: "book-id2",
type: "book",
year: "2013"
}
]