[英]Deserialize a javax.json.JsonObject
Through a rest service that @Consumes(MediaType.APPLICATION_JSON)
i get a JSON object like this 通过@Consumes(MediaType.APPLICATION_JSON)
服务,我得到了这样的JSON对象
{
"key": "myKey",
"value": {
"port": 1234,
"username": "JimmyTest5",
"password": "password123",
"host": "http://myurl.com",
}
}
In my java code i need this JSON to be inserted into the class : 在我的Java代码中,我需要将此JSON插入到类中:
public class Input {
@JsonProperty("key")
private String key;
@JsonProperty("value")
private JsonObject value;
protected Input () {
}
public Input (String key, JsonObject value) {
this.key = key;
this.value = value;
}
public String getKey() {
return key;
}
public JsonObject getValue() {
return value;
}}
The JsonObject type is mandatory. JsonObject类型是必需的。 Sadly I can't find any method to make it work. 可悲的是,我找不到任何使其工作的方法。 The error I get is 我得到的错误是
Caused by: java.util.concurrent.CompletionException: javax.ws.rs.ProcessingException: com.fasterxml.jackson.databind.JsonMappingException: Can not find a deserializer for non-concrete Map type [map type; 引起原因:java.util.concurrent.CompletionException:javax.ws.rs.ProcessingException:com.fasterxml.jackson.databind.JsonMappingException:找不到非具体Map类型的反序列化器。 class javax.json.JsonObject, [simple type, class java.lang.String] -> [simple type, class javax.json.JsonValue]] 类javax.json.JsonObject,[简单类型,类java.lang.String]-> [简单类型,类javax.json.JsonValue]
The problem is defined in this line of error: 该问题在以下错误行中定义:
Can not find a deserializer for non-concrete Map type
Faster jackson don't know what concrete class to use for the field value. 更快的杰克逊不知道该字段值使用哪个具体类。
Replace it with a Map
and initialize value in the constructor with a concrete Map
, Hashmap
for example. 用Map
替换它,并使用具体的Map
(例如Hashmap
在构造函数中初始化值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.