Java REST API: Can not deserialize instance of Object out of START_ARRAY token -
i have rest api written using java , jersey. below related code of web api.
@get @path("/getallphase1") @produces(mediatype.application_json) public list<phase1bean> getallphase1() { phase1interface phase1interface = new phase1impl(); list<phase1bean> allphase1 = phase1interface.getallphase1(); return allphase1; }
in web application's rest client, wrote below code.
client client = clientbuilder.newclient(); client.target("http://localhost:8080/xxx/rest") .path("phase1/getallphase1") .request(mediatype.application_json) .get(phase1bean.class);
unfortunatly generates below error
exception in thread "main" javax.ws.rs.client.responseprocessingexception: com.fasterxml.jackson.databind.jsonmappingexception: can not deserialize instance of bean.phase1bean out of start_array token @ [source: org.glassfish.jersey.message.internal.readerinterceptorexecutor$uncloseableinputstream@2fb3536e; line: 1, column: 1] @ org.glassfish.jersey.client.jerseyinvocation.translate(jerseyinvocation.java:806) @ org.glassfish.jersey.client.jerseyinvocation.access$700(jerseyinvocation.java:92) @ org.glassfish.jersey.client.jerseyinvocation$2.call(jerseyinvocation.java:700) @ org.glassfish.jersey.internal.errors.process(errors.java:315) @ org.glassfish.jersey.internal.errors.process(errors.java:297) @ org.glassfish.jersey.internal.errors.process(errors.java:228) @ org.glassfish.jersey.process.internal.requestscope.runinscope(requestscope.java:444) @ org.glassfish.jersey.client.jerseyinvocation.invoke(jerseyinvocation.java:696) @ org.glassfish.jersey.client.jerseyinvocation$builder.method(jerseyinvocation.java:420) @ org.glassfish.jersey.client.jerseyinvocation$builder.get(jerseyinvocation.java:316) @ jerseyclientget.main(jerseyclientget.java:32) caused by: com.fasterxml.jackson.databind.jsonmappingexception: can not deserialize instance of bean.phase1bean out of start_array token @ [source: org.glassfish.jersey.message.internal.readerinterceptorexecutor$uncloseableinputstream@2fb3536e; line: 1, column: 1] @ com.fasterxml.jackson.databind.jsonmappingexception.from(jsonmappingexception.java:164) @ com.fasterxml.jackson.databind.deserializationcontext.mappingexception(deserializationcontext.java:691) @ com.fasterxml.jackson.databind.deserializationcontext.mappingexception(deserializationcontext.java:685) @ com.fasterxml.jackson.databind.deser.beandeserializerbase.deserializefromarray(beandeserializerbase.java:1215) @ com.fasterxml.jackson.databind.deser.beandeserializer._deserializeother(beandeserializer.java:151) @ com.fasterxml.jackson.databind.deser.beandeserializer.deserialize(beandeserializer.java:126) @ com.fasterxml.jackson.databind.objectreader._bind(objectreader.java:1233) @ com.fasterxml.jackson.databind.objectreader.readvalue(objectreader.java:677) @ com.fasterxml.jackson.jaxrs.base.providerbase.readfrom(providerbase.java:777) @ 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) ... 10 more java result: 1
how can solve issue?
your method returning list, rather single phase1bean object - hence "start_array" token mentioned in error message. can change client .get()
method receive list, , extract phase1bean items there.
client.target("http://localhost:8080/xxx/rest") .path("phase1/getallphase1") .request(mediatype.application_json) .get(new generictype<list<phase1bean>>(){});
an alternative wrap list in object (phase1beanresponse, example), containing list , possibly other metadata related items.
Comments
Post a Comment