我有以下课程:
class A{
String abc;
String def;
// appropriate getters and setters with JsonProperty Annotation
}
Run Code Online (Sandbox Code Playgroud)
我打电话给Jacksons objectMapper.writeValueAsString(A)哪个工作正常.
现在我需要添加另一个实例成员:
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
}
Run Code Online (Sandbox Code Playgroud)
但是当我序列化时,我会遇到异常:
org.codehaus.jackson.map.JsonMappingException: No serializer found for class org.json.JSONObject and no properties discovered to create BeanSerializer
Run Code Online (Sandbox Code Playgroud)
我尝试了JSONNode,但它将Output作为{outerjson:" {innerjson} " }而不是{outerjson:{innerjson}}.
是否可以使用Jackson实现上述输出,即JSONObject中的JSONObject?
