相关疑难解决方法(0)

JSON - 无法使用Jackson在Object中序列化JSONObject

我有以下课程:

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?

在此输入图像描述

java serialization json jackson

8
推荐指数
2
解决办法
1万
查看次数

标签 统计

jackson ×1

java ×1

json ×1

serialization ×1