通過一個REST服務,@Consumes(MediaType.APPLICATION_JSON)
我得到這樣反序列化javax.json.JsonObject
{
"key": "myKey",
"value": {
"port": 1234,
"username": "JimmyTest5",
"password": "password123",
"host": "http://myurl.com",
}
}
一個JSON對象,在我的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;
}}
JsonObject類型是強制性的。 可悲的是我找不到任何方法使它工作。我得到的錯誤是
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; class javax.json.JsonObject, [simple type, class java.lang.String] -> [simple type, class javax.json.JsonValue]]
創建一個自定義的Pojo而不是做*** JsonObject的值*** –
我沒有這個選項,因爲JsonObject是強制性的。 – user3525227