5 Replies Latest reply on Nov 16, 2012 10:04 AM by csa

    Problem with Jackson demarshalling.

    htfv

      Hello everyone!

       

      I have 2 simple objects:

       

      @Portable
      public class FindTranslationsResult
      {
          @NonPortable
          public static class Builder
          {
              private List<TranslationDto> translations;
              ...
          }
      
          private final List<TranslationDto> translations;
      
          protected FindTranslationsResult(final Builder builder)
          {
              this(builder.translations);
          }
      
          protected FindTranslationsResult(
                  @MapsTo("translations") final List<TranslationDto> translations)
          {
              this.translations = translations;
          }
      
          public List<TranslationDto> getTranslations()
          {
              return translations;
          }
      }
      
      @Portable
      public class TranslationDto
      {
          @NonPortable
          public static class Builder
          {
              private Integer id;
              private String name;
              ...
          }
      
          private final Integer id;
          private final String name;
      
          protected TranslationDto(final Builder builder)
          {
              this(builder.id, builder.name);
          }
      
          protected TranslationDto(
                  @MapsTo("id") final Integer id,
                  @MapsTo("name") final String name)
          {
              this.id   = id;
              this.name = name;
          }
      
          public Integer getId()
          {
              return id;
          }
      
          public String getName()
          {
              return name;
          }
      }
      

       

      When a REST service returns FindTranslationsResult, it is returned as follows:

       

      {"translations":[{"id":1,"name":"test-1"},{"id":2,"name":"test-2"}]}
      

       

      The problem is that when FindTranslationResult is demarshalled on the client side, the FindTranslationsResult.translations list contains HashMap's, not TranslationDto's. Is there a way to tell the marshaller that translations is a list of TranslationDto's?

       

       

      Regards

        • 1. Re: Problem with Jackson demarshalling.
          htfv

          BTW, I tried to replace List<TranslationDto> with TranslationDto[] and I get exception during compilation:

           

          [ERROR] org.jboss.errai.marshalling.client.api.exceptions.MarshallingException: no marshaller for type: [Lcom.brandmaker.languagecenter.ui.rest.shared.dto.TranslationDto;
          [ERROR]     at org.jboss.errai.marshalling.rebind.api.impl.defaultjava.DefaultJavaMappingStrategy$1.getMarshaller(DefaultJavaMappingStrategy.java:176)
          [ERROR]     at org.jboss.errai.marshalling.rebind.MarshallerGeneratorFactory.addMarshaller(MarshallerGeneratorFactory.java:313)
          [ERROR]     at org.jboss.errai.marshalling.rebind.MarshallerGeneratorFactory.generateMarshallers(MarshallerGeneratorFactory.java:296)
          [ERROR]     at org.jboss.errai.marshalling.rebind.MarshallerGeneratorFactory._generate(MarshallerGeneratorFactory.java:268)
          [ERROR]     at org.jboss.errai.marshalling.rebind.MarshallerGeneratorFactory.generate(MarshallerGeneratorFactory.java:142)
          [ERROR]     at org.jboss.errai.marshalling.rebind.MarshallersGenerator._generate(MarshallersGenerator.java:271)
          [ERROR]     at org.jboss.errai.marshalling.rebind.MarshallersGenerator.generateMarshallerBootstrapper(MarshallersGenerator.java:249)
          [ERROR]     at org.jboss.errai.marshalling.rebind.MarshallersGenerator.generate(MarshallersGenerator.java:234)
          ...
          

           

          Are arrays not supported?

           

          For info: this is GWT 2.5.0 and Errai 2.1.1.Final. Had the same errors with GWT 2.5.0-rc2 and Errai 2.1.0.Final.

          • 2. Re: Problem with Jackson demarshalling.
            csa

            Hi Aliaksei,

             

            The latter (the array-specific problem) was a simple bug in our marshaller generator. It's fixed now in the latest 2.2.0-SNAPSHOT. See https://issues.jboss.org/browse/ERRAI-435.

             

            I understand what causes the problem with @MapsTo and List<T> when using Jackson. I am working on a solution.

             

            Thanks for reporting these issues,

            Christian

            1 of 1 people found this helpful
            • 3. Re: Problem with Jackson demarshalling.
              csa

              OK the first problem (using @MapsTo with Lists) is fixed now as well in the latest 2.2.0-SNAPSHOTs:  https://issues.jboss.org/browse/ERRAI-436

               

              Cheers,

              Christian

              • 4. Re: Problem with Jackson demarshalling.
                htfv

                Thanks for the quick response. I was going to try RestyGWT but now it works with Errai.

                 

                Any chances to get https://issues.jboss.org/browse/ERRAI-414 fixed?

                 

                 

                Regards,

                Aliaksei

                • 5. Re: Problem with Jackson demarshalling.
                  csa

                  Hi,

                   

                  Yes we will fix ERRAI-414. In fact, I wanted to do it for a while now, but it might require some breaking changes, which is why it will probably be in Errai 3.

                   

                  Cheers,

                  Christian