5 Replies Latest reply on Oct 12, 2012 9:19 AM by csa

    Demarshalling exception for int value

    magix

      Hi,

       

      I'm calling an JAX-RS webservice (external to my errai project). I'm able to call it if it returns only String-values.

      But whenever the returned entity contains numbers (like int or Integer) I get the following exception:

       

      11:07:19.000 [ERROR] [App] Uncaught exception escaped

       

       

      java.lang.RuntimeException: error demarshalling entity: it.errai.client.shared.Snapshot

          at org.jboss.errai.marshalling.client.api.MarshallerFactoryImpl$9.demarshall(MarshallerFactoryImpl.java:648)

          at org.jboss.errai.marshalling.client.api.MarshallerFactoryImpl$9.demarshall(MarshallerFactoryImpl.java:1)

          at org.jboss.errai.marshalling.client.Marshalling.fromJSON(Marshalling.java:153)

          at org.jboss.errai.enterprise.client.jaxrs.MarshallingWrapper.fromJSON(MarshallingWrapper.java:56)

          at org.jboss.errai.enterprise.client.jaxrs.JaxrsProxyLoaderImpl$1SnapshotServiceImpl$1.onResponseReceived(JaxrsProxyLoaderImpl.java:88)

          at com.google.gwt.http.client.Request.fireOnResponseReceived(Request.java:287)

          at com.google.gwt.http.client.RequestBuilder$1.onReadyStateChange(RequestBuilder.java:395)

          at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

          at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)

          at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

          at java.lang.reflect.Method.invoke(Unknown Source)

          at com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:103)

          at com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:71)

          at com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:172)

          at com.google.gwt.dev.shell.BrowserChannelServer.reactToMessagesWhileWaitingForReturn(BrowserChannelServer.java:337)

          at com.google.gwt.dev.shell.BrowserChannelServer.invokeJavascript(BrowserChannelServer.java:218)

          at com.google.gwt.dev.shell.ModuleSpaceOOPHM.doInvoke(ModuleSpaceOOPHM.java:136)

          at com.google.gwt.dev.shell.ModuleSpace.invokeNative(ModuleSpace.java:561)

          at com.google.gwt.dev.shell.ModuleSpace.invokeNativeObject(ModuleSpace.java:269)

          at com.google.gwt.dev.shell.JavaScriptHost.invokeNativeObject(JavaScriptHost.java:91)

          at com.google.gwt.core.client.impl.Impl.apply(Impl.java)

          at com.google.gwt.core.client.impl.Impl.entry0(Impl.java:213)

          at sun.reflect.GeneratedMethodAccessor37.invoke(Unknown Source)

          at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

          at java.lang.reflect.Method.invoke(Unknown Source)

          at com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:103)

          at com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:71)

          at com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:172)

          at com.google.gwt.dev.shell.BrowserChannelServer.reactToMessages(BrowserChannelServer.java:292)

          at com.google.gwt.dev.shell.BrowserChannelServer.processConnection(BrowserChannelServer.java:546)

          at com.google.gwt.dev.shell.BrowserChannelServer.run(BrowserChannelServer.java:363)

          at java.lang.Thread.run(Unknown Source)

      Caused by: java.lang.NullPointerException: null

          at org.jboss.errai.marshalling.client.marshallers.IntegerMarshaller.doNotNullDemarshall(IntegerMarshaller.java:48)

          at org.jboss.errai.marshalling.client.marshallers.IntegerMarshaller.doNotNullDemarshall(IntegerMarshaller.java:1)

          at org.jboss.errai.marshalling.client.marshallers.AbstractNullableMarshaller.demarshall(AbstractNullableMarshaller.java:19)

          at org.jboss.errai.marshalling.client.api.MarshallerFactoryImpl$9.demarshall(MarshallerFactoryImpl.java:625)

          at org.jboss.errai.marshalling.client.api.MarshallerFactoryImpl$9.demarshall(MarshallerFactoryImpl.java:1)

          at org.jboss.errai.marshalling.client.Marshalling.fromJSON(Marshalling.java:153)

          at org.jboss.errai.enterprise.client.jaxrs.MarshallingWrapper.fromJSON(MarshallingWrapper.java:56)

          at org.jboss.errai.enterprise.client.jaxrs.JaxrsProxyLoaderImpl$1SnapshotServiceImpl$1.onResponseReceived(JaxrsProxyLoaderImpl.java:88)

          at com.google.gwt.http.client.Request.fireOnResponseReceived(Request.java:287)

          at com.google.gwt.http.client.RequestBuilder$1.onReadyStateChange(RequestBuilder.java:395)

          at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

          at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)

          at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

          at java.lang.reflect.Method.invoke(Unknown Source)

          at com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:103)

          at com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:71)

          at com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:172)

          at com.google.gwt.dev.shell.BrowserChannelServer.reactToMessagesWhileWaitingForReturn(BrowserChannelServer.java:337)

          at com.google.gwt.dev.shell.BrowserChannelServer.invokeJavascript(BrowserChannelServer.java:218)

          at com.google.gwt.dev.shell.ModuleSpaceOOPHM.doInvoke(ModuleSpaceOOPHM.java:136)

          at com.google.gwt.dev.shell.ModuleSpace.invokeNative(ModuleSpace.java:561)

          at com.google.gwt.dev.shell.ModuleSpace.invokeNativeObject(ModuleSpace.java:269)

          at com.google.gwt.dev.shell.JavaScriptHost.invokeNativeObject(JavaScriptHost.java:91)

          at com.google.gwt.core.client.impl.Impl.apply(Impl.java)

          at com.google.gwt.core.client.impl.Impl.entry0(Impl.java:213)

          at sun.reflect.GeneratedMethodAccessor37.invoke(Unknown Source)

          at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

          at java.lang.reflect.Method.invoke(Unknown Source)

          at com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:103)

          at com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:71)

          at com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:172)

          at com.google.gwt.dev.shell.BrowserChannelServer.reactToMessages(BrowserChannelServer.java:292)

          at com.google.gwt.dev.shell.BrowserChannelServer.processConnection(BrowserChannelServer.java:546)

          at com.google.gwt.dev.shell.BrowserChannelServer.run(BrowserChannelServer.java:363)

          at java.lang.Thread.run(Unknown Source)

        • 1. Re: Demarshalling exception for int value
          csa

          Hi Matthias,

           

          What response format are you using on the server? You can either deploy the errai-jaxrs-provider to use Errai's JSON format or use Jackson. For the latter you have to activate Jackson compatibilty mode on the client, see: https://docs.jboss.org/author/display/ERRAI/Errai+JAX-RS+Configuration

           

          In both cases, you're use case should work of course. If it doesn't, can you post the source of the entity that causes this problem?

           

          Cheers,

          Christian

          • 2. Re: Demarshalling exception for int value
            magix

            Hi Christian,

             

            I'm using json, my jax-rs interface looks like this:

             

            @Path("snapshot")

            public interface SnapshotService {

             

             

                      @GET

                      @Produces(MediaType.APPLICATION_JSON)

                      public Snapshot get();

             

            }

             

            and the entity itself is this:

             

            @Portable

            public class Snapshot implements Serializable {

             

             

                      int myfield;

             

                      public int getMyfield() {

                                return myfield;

                      }

             

                      public void setMyfield(int myfield) {

                                this.myfield = myfield;

                      }

             

            }

             

            On the client I already have activated Jackson-compatibility. If I use a ResponseCallback, response.getText() returns for example {"myfield":"1"}, when I change to RemoteCallback I get the error listed in my first post.

             

            If I use a fake implementation of this interface in errai, it works. But the serialized response sent to the client in this case is not Json but an Errai-specific format, right?

            • 3. Re: Demarshalling exception for int value
              csa

              It's JSON in both cases. It's important though to only enable Jackson on the client if your server returns a Jackson compatible JSON. If your server returns Errai's JSON (because you deployed the errai-jaxrs-provider) then nothing needs to be done on the client.

               

              What is your server returning? Maybe it's returning a different JSON format (e.g. Jettison).

              • 4. Re: Demarshalling exception for int value
                magix

                You're right. It's not Jackson-format, but something else.

                I setup an example Rest-service with Jackson-marshalling and there it works.

                 

                But in my case I can't change the Rest-service. So this means I can't use errai unmarshalling on the client but I have to parse the response myself?

                • 5. Re: Demarshalling exception for int value
                  csa

                  Hi Matthias,

                   

                  Yes, we support Jackson and our own JSON format. If some other format is returned from the server and you can't change it you will have to parse the response yourself, unfortunately.

                   

                  Christian