2 Replies Latest reply on Jan 2, 2013 11:02 PM by csa

    Problem demarshalling Map

    davidka

      Hello everyone!

       

      I have a resolver class which inlcudes a map with translations:

       

      @Portable
      public class TranslationResolver {
      
          public TranslationResolver(){}
      
          private Map<String, Map<String, String>> translations;
      
          public Map<String, Map<String, String>> getTranslations() {
              return translations;
          }
      
          public void setTranslations(Map<String, Map<String, String>> translations) {
              this.translations = translations;
          }
      }
      

       

      and a service which has methods to return the resolver or the map from the resolver:

       

      @Service
      public class RPCDemoService implements TranslationRemoteService {
      
          @Override
          public TranslationResolver getResolver() {
              TranslationResolver transResolver = new TranslationResolver();
      
              Map<String, Map<String, String>> allTranslations = getTranslations();
              transResolver.setTranslations(allTranslations);
      
              return transResolver;
          }
      
          @Override
          public Map<String, Map<String, String>> getTranslations() {
              //create map for german translations
              Map<String, String> deTranslations = new HashMap<String, String>();
              deTranslations.put("hello", "Hallo");
              deTranslations.put("one", "Eins");
      
              //create map for english translations
              Map<String, String> enTranslations = new HashMap<String, String>();
              enTranslations.put("hello", "Hello");
              enTranslations.put("one", "One");
      
              //put the translations together
              Map<String, Map<String, String>> allTranslations = new HashMap<String, Map<String,String>>();
              allTranslations.put("de", deTranslations);
              allTranslations.put("en", enTranslations);
      
              return allTranslations;
          }
      
      }
      

       

      When i call the getTranslations() method through a rpc proxy, i get the correct translations:

      Translations: {de={hello=Hallo, one=Eins}, en={hello=Hello, one=One}}
      

       

      But when i call the getResolver() method, the values of the inner map are null:

      Translations: {de={hello=null, one=null}, en={hello=null, one=null}}
      

       

      I found out, tha if I create a custom marshaller, copy content from generated marshaller (ServerMarshallingFactoryImpl.java) and delete the commented (setAssumedMapKeyType and setAssumedMapValueType) lines, it works:

       

      ...
      public TranslationResolver demarshall(EJValue a0, MarshallingSession a1) {
              try {
                if (a0.isNull()) {
                  return null;
                }
                EJObject obj = a0.isObject();
                String objId = obj.get("^ObjectID").isString().stringValue();
                if (a1.hasObject(objId)) {
                  return a1.getObject(TranslationResolver.class, objId);
                }
                TranslationResolver entity = new TranslationResolver();
                a1.recordObject(objId, entity);
                if ((obj.containsKey("translations")) && (!obj.get("translations").isNull())) {
                  //a1.setAssumedMapKeyType("java.lang.String");
                  //a1.setAssumedMapValueType("java.util.Map");
                  entity.setTranslations((Map) java_util_Map.demarshall(obj.get("translations"), a1));
                  //a1.setAssumedMapKeyType(null);
                  //a1.setAssumedMapValueType(null);
                }
                return entity;
              } catch (Throwable t) {
                t.printStackTrace();
                throw new RuntimeException("error demarshalling entity: org.errai.samples.rpcdemo.client.shared.TranslationResolver", t);
              }
            }
      ...
      

       

       

      I've attached a sample, which extends your RPC Demo and shows the problem

        • 1. Re: Problem demarshalling Map
          jfuerth

          Hi David,

           

          Thanks very much for digging into this issue and reporting it to us. I've filed ERRAI-463 and scheduled it to be resolved for 2.2.0.Final. If you sign yourself up as a watcher for that bug, you should get a notification when it's fixed in 2.2.0-SNAPSHOT. It'll probably not be until early January, because the Errai team are all on vacation next week.

           

          Thanks again,

          Jonathan

          • 2. Re: Problem demarshalling Map
            csa

            Hi,

             

            This should be fixed now (in the latest 2.2.0-SNAPSHOTs).

             

            Thanks,

            Christian