JSON避难所化问题:错误的json值为类型
我有一个类似于下面的复合对象:
Map<String, Object> m = new HashMap<>();
m.put("a", "b");
m.put("c", "{\"a\" :3, \"b\" : 5}");
m = {a=b, c={"a" :3, "b" : 5}}
我必须通过https调用提交此请求,以便对Java对象进行应序列化,因此我将其转换为JSON字符串,使用,
objectmapper.writeValueAsString(m)
当我转换时,它将其附加到C的值中。 :
{"a":"b","c":"{\"a\" :3, \"b\" : 5}"}
在客户端进行对象的挑选时,请求未能说 “错误的JSON值为类型:类”
任何帮助?
I have a composite object like below:
Map<String, Object> m = new HashMap<>();
m.put("a", "b");
m.put("c", "{\"a\" :3, \"b\" : 5}");
m = {a=b, c={"a" :3, "b" : 5}}
I have to submit this request via https call in order to deserialize to a java object, hence i converted this to JSON string, using,
objectmapper.writeValueAsString(m)
when i convert it , it is appending quotes to the value of c:
{"a":"b","c":"{\"a\" :3, \"b\" : 5}"}
and While deserializing this object at the client side, the request fails saying
"Error deserialize JSON value into type: class"
Any help??
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
值的类型
c
是字符串,因此对象映射器逃脱了所有非法字符,将字符串包裹在引号中。您可以制作
c
另一个映射:或者您可以创建自定义pojo并使用 @jsonrawvalue 注释:
从 documentation :
客户端错误的含义可能是它无法将字符串归为对象(它期望
{
而不是“
)。The type of the value
C
is String, so the object mapper escapes all illegal characters a wraps the string in quotes.You could make
C
an another map:Or you can create custom POJO and use @JsonRawValue annotation:
From the documentation:
The client error meaning probably is that it can't deserialize String into an Object (it expects
{
instead of"
).您最好将
JSONOBJECT
用于c
值:完成代码:
输出为:
You better use
JSONObject
forc
value:Complete code:
The output is: