java - JsonMappingException: Can not find a deserializer for non-concrete Map type -
string str = commonclient.authorizedrequestbuilder(commonclient.webtarget .path("/apps/get_current_version/default/"+appname+"/"+appname) .queryparam("object_type", "app")) .accept(mediatype.application_json_type) .get() .readentity(string.class);
i
str = {"versions": {"ap": "not set", "am": "topic-test-publisher-1.0.16", "il": "topic-test-publisher-1.0.16", "row": "topic-test-publisher-1.0.49"}, "provider": "gce"}
then have changed code
version version = commonclient.authorizedrequestbuilder(commonclient.webtarget .path("/apps/get_current_version/default/"+appname+"/"+appname) .queryparam("object_type", "app")) .accept(mediatype.application_json_type) .get(clientresponse.class) .readentity(new generictype<version>(){});
and got exception:
caused by: com.fasterxml.jackson.databind.jsonmappingexception: can not find deserializer non-concrete map type [map type; class javax.ws.rs.core.multivaluedmap, [simple type, class java.lang.string] -> [collection type; class java.util.list, contains [simple type, class java.lang.object]]] @ com.fasterxml.jackson.databind.deser.deserializercache._createandcache2(deserializercache.java:269) @ com.fasterxml.jackson.databind.deser.deserializercache._createandcachevaluedeserializer(deserializercache.java:244) @ com.fasterxml.jackson.databind.deser.deserializercache.findvaluedeserializer(deserializercache.java:142) @ com.fasterxml.jackson.databind.deserializationcontext.findcontextualvaluedeserializer(deserializationcontext.java:428) @ com.fasterxml.jackson.databind.deser.std.stddeserializer.finddeserializer(stddeserializer.java:947) @ com.fasterxml.jackson.databind.deser.beandeserializerbase.resolve(beandeserializerbase.java:439) @ com.fasterxml.jackson.databind.deser.deserializercache._createandcache2(deserializercache.java:296) @ com.fasterxml.jackson.databind.deser.deserializercache._createandcachevaluedeserializer(deserializercache.java:244) @ com.fasterxml.jackson.databind.deser.deserializercache.findvaluedeserializer(deserializercache.java:142) @ com.fasterxml.jackson.databind.deserializationcontext.findcontextualvaluedeserializer(deserializationcontext.java:428) @ com.fasterxml.jackson.databind.deser.std.stddeserializer.finddeserializer(stddeserializer.java:947) @ com.fasterxml.jackson.databind.deser.beandeserializerbase.resolve(beandeserializerbase.java:439) @ com.fasterxml.jackson.databind.deser.deserializercache._createandcache2(deserializercache.java:296) @ com.fasterxml.jackson.databind.deser.deserializercache._createandcachevaluedeserializer(deserializercache.java:244) @ com.fasterxml.jackson.databind.deser.deserializercache.findvaluedeserializer(deserializercache.java:142) @ com.fasterxml.jackson.databind.deserializationcontext.findrootvaluedeserializer(deserializationcontext.java:461) @ com.fasterxml.jackson.databind.objectreader._findrootdeserializer(objectreader.java:1749) @ com.fasterxml.jackson.databind.objectreader._bind(objectreader.java:1465) @ com.fasterxml.jackson.databind.objectreader.readvalue(objectreader.java:912) @ com.fasterxml.jackson.jaxrs.base.providerbase.readfrom(providerbase.java:810) @ org.glassfish.jersey.message.internal.readerinterceptorexecutor$terminalreaderinterceptor.invokereadfrom(readerinterceptorexecutor.java:256) @ org.glassfish.jersey.message.internal.readerinterceptorexecutor$terminalreaderinterceptor.aroundreadfrom(readerinterceptorexecutor.java:235) @ org.glassfish.jersey.message.internal.readerinterceptorexecutor.proceed(readerinterceptorexecutor.java:155) @ org.glassfish.jersey.message.internal.messagebodyfactory.readfrom(messagebodyfactory.java:1085) @ org.glassfish.jersey.message.internal.inboundmessagecontext.readentity(inboundmessagecontext.java:874) @ org.glassfish.jersey.message.internal.inboundmessagecontext.readentity(inboundmessagecontext.java:808) @ org.glassfish.jersey.client.clientresponse.readentity(clientresponse.java:326) @ org.glassfish.jersey.client.jerseyinvocation.translate(jerseyinvocation.java:803) ... 32 more caused by: java.lang.illegalargumentexception: can not find deserializer non-concrete map type [map type; class javax.ws.rs.core.multivaluedmap, [simple type, class java.lang.string] -> [collection type; class java.util.list, contains [simple type, class java.lang.object]]] @ com.fasterxml.jackson.databind.deser.basicdeserializerfactory.createmapdeserializer(basicdeserializerfactory.java:1158) @ com.fasterxml.jackson.databind.deser.deserializercache._createdeserializer2(deserializercache.java:380) @ com.fasterxml.jackson.databind.deser.deserializercache._createdeserializer(deserializercache.java:352) @ com.fasterxml.jackson.databind.deser.deserializercache._createandcache2(deserializercache.java:264) ... 59 more
where:
@jsonignoreproperties(ignoreunknown = true) public class version { @jsonproperty("am") public string am; @jsonproperty("row") public string row; @override public string tostring() { return "versiondto{" + "am='" + + '\'' + ", row='" + row + '\'' + '}'; } }
how can deserialize differently?
update
i have tried:
with
public class version { public map<string, string> versions; public string provider; // getters, setters, etc }
and
version version = commonclient.authorizedrequestbuilder(commonclient.webtarget .path("/apps/get_current_version/gce/waze-prod/default/"+appname+"/"+appname) .queryparam("object_type", "app")) .accept(mediatype.application_json_type) .get(clientresponse.class) .readentity(version.class);
but got same error
i object version
need have field named versions
of type map<string, string>
, 1 named provider
of type string
, , don't need generictype
thing.
public class version { private map<string, string> versions; private string provider; // getters, setters, etc }
then
version version = commonclient.authorizedrequestbuilder(commonclient.webtarget) // ... .readentity(version.class); version.getversions().get("am"); // "am"
tested
import com.fasterxml.jackson.databind.objectmapper; import java.io.ioexception; import java.util.map; public class test { public static void main(string[] args) throws ioexception { string str = "{\"versions\": {\"ap\": \"not set\", \"am\": \"topic-test-publisher-1.0.16\", \"il\": \"topic-test-publisher-1.0.16\", \"row\": \"topic-test-publisher-1.0.49\"}, \"provider\": \"gce\"}"; objectmapper objectmapper = new objectmapper(); version v = objectmapper.readvalue(str, version.class); system.out.println(v.versions.get("am")); } public static class version { public map<string, string> versions; public string provider; } }
output: "topic-test-publisher-1.0.16"
Comments
Post a Comment