users@jersey.java.net

[Jersey] Re: NPE occurs in readEntity method

From: Tatu Saloranta <tsaloranta_at_gmail.com>
Date: Sun, 14 Jul 2013 14:19:25 -0700

On Sun, Jul 14, 2013 at 7:29 AM, Noritaka Sekiyama <moomindani_at_gmail.com>wrote:

> Hello Jersey Users,
>
> I'm trying to implement REST Client for 3 online strage services (Dropbox,
> GoogleDrive and SkyDrive) with Jersey 2.0.
> In order to get JSON metadata and convert JSON to DTO by MOXy, I made
> following code.
>
> -----------------------------------------
> Client client = ClientBuilder.newBuilder()
> .register(MoxyJsonFeature.class)
> .register(JsonMoxyConfigurationContextResolver.class)
> .build();
> WebTarget target = client.target(targetUrl);
> Response response = target.request(MediaType.APPLICATION_JSON_TYPE).get();
> assert response.getStatus() == 200;
> //System.out.println(response.readEntity(String.class));
> GoogleDriveMetadata metadata =
> response.readEntity(GoogleDriveMetadata.class);
> -----------------------------------------
>
> I confirm that this code works fine in Dropbox, but does not work in
> GoogleDrive and SkyDrive because of NPE.
> (Stack trace in case of GoogleDrive is shown at the end of this message. )
>
> Please tell me how to avoid NPE in the method Response.readEntity().
>
>
Try Jackson-based POJO mapping? I don't know how mature MOXy's JSON support
is, as it was started as JAXB/XML binder (AFAIK).

-+ Tatu +-



> -----------------------------------------
> java.lang.reflect.InvocationTargetException
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> at
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
> at
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
> at java.lang.reflect.Method.invoke(Method.java:606)
> at org.codehaus.mojo.exec.ExecJavaMojo$1.run(ExecJavaMojo.java:297)
> at java.lang.Thread.run(Thread.java:724)
> Caused by: java.lang.NullPointerException
> at
> org.eclipse.persistence.internal.oxm.record.json.JSONReader.parse(JSONReader.java:264)
> at
> org.eclipse.persistence.internal.oxm.record.json.JSONReader.parse(JSONReader.java:443)
> at
> org.eclipse.persistence.internal.oxm.record.json.JSONReader.parse(JSONReader.java:296)
> at
> org.eclipse.persistence.internal.oxm.record.json.JSONReader.parse(JSONReader.java:443)
> at
> org.eclipse.persistence.internal.oxm.record.json.JSONReader.parse(JSONReader.java:424)
> at
> org.eclipse.persistence.internal.oxm.record.json.JSONReader.parse(JSONReader.java:241)
> at
> org.eclipse.persistence.internal.oxm.record.json.JSONReader.parseRoot(JSONReader.java:179)
> at
> org.eclipse.persistence.internal.oxm.record.json.JSONReader.parse(JSONReader.java:125)
> at
> org.eclipse.persistence.internal.oxm.record.SAXUnmarshaller.unmarshal(SAXUnmarshaller.java:972)
> at
> org.eclipse.persistence.internal.oxm.record.SAXUnmarshaller.unmarshal(SAXUnmarshaller.java:425)
> at
> org.eclipse.persistence.internal.oxm.record.SAXUnmarshaller.unmarshal(SAXUnmarshaller.java:635)
> at
> org.eclipse.persistence.internal.oxm.record.SAXUnmarshaller.unmarshal(SAXUnmarshaller.java:703)
> at
> org.eclipse.persistence.oxm.XMLUnmarshaller.unmarshal(XMLUnmarshaller.java:655)
> at
> org.eclipse.persistence.jaxb.JAXBUnmarshaller.unmarshal(JAXBUnmarshaller.java:301)
> at
> org.eclipse.persistence.jaxb.rs.MOXyJsonProvider.readFrom(MOXyJsonProvider.java:580)
> at
> org.glassfish.jersey.message.internal.ReaderInterceptorExecutor$TerminalReaderInterceptor.aroundReadFrom(ReaderInterceptorExecutor.java:188)
> at
> org.glassfish.jersey.message.internal.ReaderInterceptorExecutor.proceed(ReaderInterceptorExecutor.java:134)
> at
> org.glassfish.jersey.message.internal.MessageBodyFactory.readFrom(MessageBodyFactory.java:988)
> at
> org.glassfish.jersey.message.internal.InboundMessageContext.readEntity(InboundMessageContext.java:833)
> at
> org.glassfish.jersey.message.internal.InboundMessageContext.readEntity(InboundMessageContext.java:768)
> at
> org.glassfish.jersey.client.InboundJaxrsResponse.readEntity(InboundJaxrsResponse.java:96)
> at
> org.glassfish.jersey.client.ScopedJaxrsResponse.access$001(ScopedJaxrsResponse.java:56)
> at
> org.glassfish.jersey.client.ScopedJaxrsResponse$1.call(ScopedJaxrsResponse.java:77)
> at org.glassfish.jersey.internal.Errors.process(Errors.java:315)
> at org.glassfish.jersey.internal.Errors.process(Errors.java:297)
> at org.glassfish.jersey.internal.Errors.process(Errors.java:228)
> at
> org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:396)
> at
> org.glassfish.jersey.client.ScopedJaxrsResponse.readEntity(ScopedJaxrsResponse.java:74)
> at
> com.clouddrive.google.GoogleDriveController.getFileList(GoogleDriveController.java:113)
> at
> com.clouddrive.google.GoogleDriveController.main(GoogleDriveController.java:182)
> ... 6 more
>
>
>
> --
> Noritaka Sekiyama
> Twitter: @moomindani
> Blog: mooapp http://moomindani.wordpress.com (
> http://moomindani.wordpress.com/)
>
>
>