6 Replies Latest reply on Jun 26, 2012 4:16 AM by Dave Fr

    NullPointerException in Marshalling.fromJSON(Marshalling.java:157)

    Dave Fr Newbie

      Hi all,

       

      I'm using the current SNAPSHOT of the errai JAXRS and I get the following exception:

       

      13:56:39.286 [ERROR] [App] Uncaught exception escaped
      java.lang.NullPointerException: null
          at org.jboss.errai.marshalling.client.Marshalling.fromJSON(Marshalling.java:157)
          at org.jboss.errai.enterprise.client.jaxrs.MarshallingWrapper.fromJSON(MarshallingWrapper.java:56)
          at org.jboss.errai.enterprise.client.jaxrs.JaxrsProxyLoaderImpl$1ISupplierServiceRemoteImpl$1.onResponseReceived(JaxrsProxyLoaderImpl.java:587)
          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.GeneratedMethodAccessor41.invoke(Unknown Source)
          at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
          at java.lang.reflect.Method.invoke(Method.java:601)
          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.GeneratedMethodAccessor39.invoke(Unknown Source)
          at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
          at java.lang.reflect.Method.invoke(Method.java:601)
          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(Thread.java:722)
      

       

      it's in

       

      public static <T> T fromJSON(String json, Class<T> type, Class<?> assumedElementType) {
          EJValue parsedValue = ParserFactory.get().parse(json);
          MarshallingSession session = MarshallingSessionProviderFactory.getDecoding();
          if (assumedElementType != null) {
            session.setAssumedElementType(assumedElementType.getName());
          }
          Marshaller<Object> marshallerInstance = session.getMarshallerInstance(type.getName());
          return (T) marshallerInstance.demarshall(parsedValue, session);
        }
      

       

      the marshallerInstance becomes null

       

      I can't debug into the MarshallerFactoryImpl class but it is generate inside the .errai folder as well as the JaxrsProxyLoaderImpl class

       

      what could be the problem?

        • 1. Re: NullPointerException in  NullPointerException
          Christian Sadilek Master

          Hi Dave,

           

          That's strange. Errai couldn't find a statically generated marshaller for the type passed to session.getMarshallerInstance(). Can you break at MarshallingWrapper.java:56 and see which type that it tries to demarshall?

           

          There should be a marshaller for that type in the generated MarshallerFactoryImpl.

           

          Cheers,

          Christian

          • 2. Re: NullPointerException in  NullPointerException
            Dave Fr Newbie

            I've found the problem.

             

            this is my original interface

             

            @Path("/supplier")
            public interface ISupplierServiceRemote {
                @GET
                @Path("/list")
                @Produces("application/json")
                public Collection<Supplier> list();
            
                @GET
                @Path("/{supplierName}/productionUnit/list")
                @Produces("application/json")
                public Collection<ProductionUnit> listProductionUnit(@PathParam("supplierName") String supplierName);
            
                @GET
                @Path("/{supplierName}/productionUnit/{productionUnitName}/products/list")
                @Produces("application/json")
                public Collection<ProductProductionUnit> listProducts(@PathParam("supplierName") String supplierName, @PathParam("productionUnitName") String productionUnitName);
            }
            

             

            It shows that it returns a Collection. After changing it to List the error is gone.

            for example:

             

            public List<Supplier> list();
            

             

            Is it possible to FIX this. Since I don't want to change already existing interfaces from a Collection to List.

            • 3. Re: NullPointerException in  NullPointerException
              Christian Sadilek Master

              Yeah the problem here is that we wouldn't know if Collection should be marshalled as a List or Set etc. You can configure an alias in ErraiApp.properties though: https://docs.jboss.org/author/display/ERRAI/Marshalling#Marshalling-AliasedMappingsofExistingInterfaceContracts

               

              errai.marshalling.mappingAliases=java.util.ArrayList->java.util.Collection

              • 4. Re: NullPointerException in  NullPointerException
                Dave Fr Newbie

                Hi Christian,

                 

                I tried out your solution, but it didn't help to solve the problem.

                 

                I put the line you suggested into my client as well as in the project with the REST interface. The marshallerInstance is still null. In the MarshallingWrapper in

                 

                public static <T> T fromJSON(String json, Class<T> type, Class<?> elementType) {
                    return Marshalling.fromJSON(_fromJSON(json), type, elementType);
                  }
                

                 

                the type is java.util.Collection

                • 5. Re: NullPointerException in  NullPointerException
                  Christian Sadilek Master

                  Hi Dave,

                   

                  I just pushed a test that confirms this functionality. However, in the example above I had the ordering wrong. It should be:

                   

                  errai.marshalling.mappingAliases=java.util.Collection->java.util.ArrayList

                   

                  Also make sure to delete your .errai directory (contains the generated and cached marshallers) so that the marshallers get re-generated.

                   

                  Cheers,

                  Christian

                  • 6. Re: NullPointerException in  NullPointerException
                    Dave Fr Newbie

                    Hi Christian,

                     

                    that was the trick, thank you for the response.

                     

                     

                    Great work with the JAX-RS and CDI in the errai framework, it simplifies the work for the communication with the server part, which was always a drawback in GWT in comparison i.e. to vaadin.