I have the following class:
class A{
String abc;
String def;
// appropriate getters and setters with JsonProperty Annotation
}
and I call Jacksons objectMapper.writeValueAsString(A)
which works fine.
Now I need to add another instance member:
class A{
String abc;
String def;
JSONObject newMember; // No, I cannot Stringify it, it needs to be JSONObject
// appropriate getters and setters with JsonProperty Annotation
}
but when I serialize, I am getting exception:
org.codehaus.jackson.map.JsonMappingException: No serializer found for class org.json.JSONObject and no properties discovered to create BeanSerializer
I tried JSONNode but it gave Output as {outerjson:"{innerjson}"} not {outerjson:{innerjson}}.
Is it possible to use Jackson to achieve the above output, i.e. JSONObject within JSONObject?