1 Reply Latest reply on Aug 13, 2014 12:41 PM by mbarkley

    Marshalling of AbstractList$Sublist

    jannis

      Hello,

       

      we encountered a problem when marshalling a bean with a generic value field:

       

      @Portable
      public class PortableValueEntity<T> {
          
          private T value;
          
          public T getValue() {
              return value;
          }
          
          public void setValue(T value) {
              this.value = value;
          }
      }
      

       

      If a sub list is passed to the value field we get the following error:" no marshalling definition available for type:java.util.AbstractList$SubList"

       

      Defining an alias like "errai.marshalling.mappingAliases=java.util.AbstractList$SubList->java.util.List" leads to an error if not running in production mode: "could not find class defined in ErraiApp.properties for mapping: java.util.AbstractList$SubList->java.util.List".

       

      If I got it correctly the problem is that in Java there is no nested class SubList in AbstractList (although there is that class in the AbstractList.java file), but the emulated class AbstractList has the nested class SubList.

       

      Is there any solution to this problem?

       

      Thanks in advance

       

      Jannis

       

       

      A test to reproduce this issue is as follows:

      Module: SubListMarshalTest

       

      <module>
        <inherits name="org.jboss.errai.common.ErraiCommon" />
        <inherits name='org.jboss.errai.marshalling.ErraiMarshalling' />
      </module>
      

       

      public class MarshalSubListClientTestGwt extends GWTTestCase {
          
          @Override
          public String getModuleName() {
              return "path.to.SubListMarshalTest";
          }
          
          @Override
          protected void gwtSetUp() throws Exception {
              super.gwtSetUp();
              MarshallerFramework.initializeDefaultSessionProvider();
          }
          
          public void testMarshallingArraysSubList() {
              PortableValueEntity<List<Integer>> entity = new PortableValueEntity<>();
              List<Integer> values = Arrays.asList(0, 1, 2, 3, 4, 5); // Also works with ArrayList and LinkedList
              List<Integer> value = values.subList(2, 4);
              entity.setValue(value);
              String json = Marshalling.toJSON(entity);
              PortableValueEntity<List<Integer>> demarshalledEntity = Marshalling.fromJSON(json, PortableValueEntity.class);
              assertEquals(value, demarshalledEntity.getValue());
          }
      }
      

      The test has to be executed in production mode.

        • 1. Re: Marshalling of AbstractList$Sublist
          mbarkley

          Hey Jannis,

           

          I've verified the problem exactly as described (thanks for being so specific!). Unfortunately there is no way to work around this (aside from wrapping your sublist in a new ArrayList) since there's no marshaller definition or alias you could make that would work in both DevMode and production mode.

           

          If you have the time, we would gladly accept a JIRA issue for this (or better yet, a pull request!).

           

          Cheers.