users@jersey.java.net

Re: [Jersey] NullPointerException reading empty JSON array

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Fri, 29 May 2009 14:44:20 -0700

Hi Chad,

It is a bug.

Jakub, who is responsible for the JSON stuff, is traveling at the
moment and it is J1 next week, so could you please log an issue so we
do not forget about this.

Thanks,
Paul.


On May 29, 2009, at 8:49 AM, Chad McHenry wrote:

> I'm getting an NPE when part of my put data has an empty array. I
> intended it to unmarshal to a List<Integer> (and I've tried with a
> List of more complex objects). Is there a way to get it to unmarshal
> an empty array into an empty List?
>
> @Path("/foo")
> @Produces(MediaType.APPLICATION_JSON)
> @Component
> @Scope("singleton")
> public class MediaResource {
> @POST
> public Response create(Foo foo) {
> ...
> }
>
>
> @XmlRootElement
> public class Foo {
> public List<Integer> barList;
> }
>
> curl -X POST -d '{"barList":[]}' -H 'Content-type: application/json'
> http://localhost/myapp/foo
>
> java.lang.NullPointerException
> at
> com
> .sun
> .jersey
> .json
> .impl.reader.Jackson2StaxReader.readNext(Jackson2StaxReader.java:179)
> at
> com
> .sun
> .jersey
> .json
> .impl.reader.Jackson2StaxReader.readNext(Jackson2StaxReader.java:106)
> at
> com
> .sun
> .jersey
> .json.impl.reader.Jackson2StaxReader.next(Jackson2StaxReader.java:232)
> at
> com
> .sun
> .xml
> .bind
> .v2
> .runtime
> .unmarshaller.StAXStreamConnector.bridge(StAXStreamConnector.java:192)
> at
> com
> .sun
> .xml
> .bind
> .v2
> .runtime
> .unmarshaller.UnmarshallerImpl.unmarshal0(UnmarshallerImpl.java:360)
> at
> com
> .sun
> .xml
> .bind
> .v2
> .runtime
> .unmarshaller.UnmarshallerImpl.unmarshal(UnmarshallerImpl.java:339)
> at
> com
> .sun
> .jersey.json.impl.JSONUnmarshaller.unmarshal(JSONUnmarshaller.java:
> 100)
> at
> com
> .sun
> .jersey
> .json
> .impl
> .provider
> .entity
> .JSONRootElementProvider.readFrom(JSONRootElementProvider.java:104)
> at
> com
> .sun
> .jersey
> .core
> .provider
> .jaxb
> .AbstractRootElementProvider
> .readFrom(AbstractRootElementProvider.java:97)
> at
> com
> .sun
> .jersey
> .spi.container.ContainerRequest.getEntity(ContainerRequest.java:391)
> at
> com
> .sun
> .jersey.server.impl.model.method.dispatch.EntityParamDispatchProvider
> $EntityInjectable.getValue(EntityParamDispatchProvider.java:81)
> at
> com
> .sun
> .jersey.server.impl.model.method.dispatch.EntityParamDispatchProvider
> $EntityParamInInvoker.getParams(EntityParamDispatchProvider.java:99)
> at
> com
> .sun
> .jersey.server.impl.model.method.dispatch.EntityParamDispatchProvider
> $TypeOutInvoker._dispatch(EntityParamDispatchProvider.java:136)
> at
> com
> .sun
> .jersey
> .server
> .impl
> .model
> .method
> .dispatch
> .ResourceJavaMethodDispatcher
> .dispatch(ResourceJavaMethodDispatcher.java:67)
> at
> com
> .sun
> .jersey
> .server.impl.uri.rules.HttpMethodRule.accept(HttpMethodRule.java:154)
> at
> com
> .sun
> .jersey
> .server
> .impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:111)
> at
> com
> .sun
> .jersey
> .server
> .impl.uri.rules.ResourceClassRule.accept(ResourceClassRule.java:71)
> at
> com
> .sun
> .jersey
> .server
> .impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:111)
> at
> com
> .sun
> .jersey
> .server
> .impl
> .uri
> .rules.RootResourceClassesRule.accept(RootResourceClassesRule.java:63)
> at
> com
> .sun
> .jersey
> .server
> .impl
> .application
> .WebApplicationImpl._handleRequest(WebApplicationImpl.java:543)
> at
> com
> .sun
> .jersey
> .server
> .impl
> .application
> .WebApplicationImpl.handleRequest(WebApplicationImpl.java:502)
> at
> com
> .sun
> .jersey
> .server
> .impl
> .application
> .WebApplicationImpl.handleRequest(WebApplicationImpl.java:493)
> at
> com
> .sun
> .jersey.spi.container.servlet.WebComponent.service(WebComponent.java:
> 308)
> at
> com
> .sun
> .jersey
> .spi
> .container.servlet.ServletContainer.service(ServletContainer.java:314)
> at
> com
> .sun
> .jersey
> .spi
> .container.servlet.ServletContainer.service(ServletContainer.java:239)
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>