4 Replies Latest reply on Nov 8, 2012 10:13 AM by lewarrior22

    Demarshalling fails on null enum value

    nva

      I just upgraded to Errai 2.1.1.Final and demarshalling null enum values fails with the NullPointerException inside of the generated marshaller. This worked in previous versions.

       

      A simple example:

       

       

      @Portable

      public enum Test {

       

          A,

          B;

      }

       

       

      @Portable

      public class Dto {

       

          private Test test;

       

          public Dto(@MapsTo("test") Test test) {

       

              this.test = test;

          }

       

          public Test getTest() {

       

              return test;

          }

      }

       

      When the Dto is instantiated like this, then demarshalling works:

       

      Dto dto = new Dto(A);

       

      However, when the Dto is instantiated like this, a NullPointerException is thrown on the client during demarshalling:

       

      Dto dto = new Dto(null);

        • 1. Re: Demarshalling fails on null enum value
          csa

          Thanks, Valentin. This is fixed now in the latest 2.2.0-SNAPSHOTs.

          • 2. Re: Demarshalling fails on null enum value
            lewarrior22

            Hi, Just got the same problem with int property.

             

            //When using this, The demarchalling Fail (Note the use of int id ), I have an Demarchalling Error; message = null and exception class is ResponseException.

             

            @Portable

            @Bindable

            public class Account {

            private int id ;

                      private String name ;

            @NotNull

                      private String login ;

            @NotNull

                      private String password ;

                      private String email ;

            @NotNull

                      private String website ;

             

             

                      public Account() {

                      }

             

             

                      public Account(int id, String name, String login, String password,

                                          String email, String website) {

                                super();

                                this.id = id;

                                this.name = name;

                                this.login = login;

                                this.password = password;

                                this.email = email;

                                this.website = website;

                      }

                 //getters + setters

             

                 //toString

             

            }

             

            //And when I use this bean everything is correct.

             

            /**

            * @author boris

            *

            */

            @Portable

            @Bindable

            public class Account {

                      private String name ;

            @NotNull

                      private String login ;

            @NotNull

                      private String password ;

                      private String email ;

            @NotNull

                      private String website ;

             

             

                      public Account() {

              // TODO Auto-generated constructor stub

                      }

             

             

                      public Account(int id, String name, String login, String password,

                                          String email, String website) {

                                super();

                                this.name = name;

                                this.login = login;

                                this.password = password;

                                this.email = email;

                                this.website = website;

                      }

             


                 //getters + setters

             

                 //toString

             

             

            }

            • 3. Re: Demarshalling fails on null enum value
              nva

              Hi Boris, does it also happen when you change your 'int' field to 'Integer'? Java primitives do not support null values and 'int a = null' will always give you a null pointer exception.

               

              Cheers,

               

              V.

              • 4. Re: Demarshalling fails on null enum value
                lewarrior22

                Hi,
                Yeah, the same problem occur, event with Long and Integer. It work fine only with String values. If I can post my code here :

                @Portable

                @Bindable

                publicclass Account {

                 

                private Long id ;

                 

                private String name ;

                @NotNull

                private String login ;

                @NotNull

                private String password ;

                private String email ;

                @NotNull

                private String website ;

                 

                 

                public Account() {

                // TODO Auto-generated constructor stub

                }

                 

                public Account(Long id, String name, String login, String password,

                String email, String website) {

                super();

                this.id = id;

                this.name = name;

                this.login = login;

                this.password = password;

                this.email = email;

                this.website = website;

                }

                //getters and setters , toString()

                }

                 

                //in the sample.local.share package

                @Path("/accounts")

                public interface AccountRESTService {

                @POST

                @Produces(MediaType.APPLICATION_JSON)

                @Consumes(MediaType.APPLICATION_JSON)

                public Account create(Account account) ;

                 

                @PUT

                @Produces(MediaType.APPLICATION_JSON)

                @Consumes(MediaType.APPLICATION_JSON)

                public Account update(Account account) ;

                //others methods

                }

                //and the implementation in the .sample.rest

                public class SimpleAccountRESTService implements AccountRESTService{

                 

                @Override

                public Account create(Account account) {

                System.out.println("Account Received From client   "+account);

                account.setName("creation success");

                return account;

                }

                 

                @Override

                public Account update(Account account) {

                 

                System.out.println("\n Account Received For Update client   "+account);

                account.setName("update success");

                return account;

                }

                //others methods implementations

                 

                }

                 

                //here is how .sample.client.local

                 

                @Templated("#createAccountView")

                public class CreateAccountView extends Composite {

                 

                 

                @Inject

                @Bound

                @DataField

                private TextBox id ;

                 

                @Inject

                @Bound

                @DataField

                private TextBox name ;

                 

                //..others  TextBox

                 

                @Inject

                @AutoBound

                private DataBinder<Account> accountDataBinder ;

                @Inject

                private Caller<AccountRESTService> accountRestServiceCaller ;

                 

                @EventHandler("btnSave")

                public void onBtnSaveClicked(ClickEvent click){

                     //use the model to retrieve data from the form

                     Account account = accountDataBinder.getModel();

                               Window.alert("Save acount "+account+"  \n path"+RestClient.getApplicationRoot());

                          RemoteCallback<Account> remoteCallback = new RemoteCallback<Account>() {

                     @Override

                     public void callback(Account response) {

                          Window.alert("Account Created from server !"+response);

                          }

                     };

                ErrorCallback errorCallback = new ErrorCallback() {

                 

                          @Override

                          publicboolean error(Message message, Throwable throwable) {

                               if(throwable instanceof TransportIOException){

                 

                                    Window.alert("Could Reach the server : ["+message+"]  \n and ["+throwable+"]" );

                               }else {

                 

                                    Window.alert("Marschalling errors ["+message+"]  \n and ["+throwable+"]" );

                               }

                               returnt rue;

                          }

                     };

                          RestClient.setJacksonMarshallingActive(true);

                          accountRestServiceCaller.call(remoteCallback, errorCallback).create(account);

                          Account update = accountRestServiceCaller.call(remoteCallback,errorCallback).update(account)

                     }

                }

                 

                I have my System.out.println() in JbossAS7's console. but I can't retrieve the returned account in the remoteCallBack object. @See the errorCallBack.

                 

                 

                Now I waiting the version 2.2.0.SNAPSHOT been released ! And try again.

                 

                Thanks,