2 Replies Latest reply: Jan 2, 2013 11:02 PM by Christian Sadilek RSS

    Problem demarshalling Map

    David Hahn Newbie

      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