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

    Problem with Jackson demarshalling.

    Aliaksei Lahachou Newbie

      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