0 Replies Latest reply on Jan 21, 2015 10:56 AM by luca.masini

    Cannot understand @Key annotation on Portable entity

    luca.masini

      I need to change the name of a property that must be deserialized from a custom JSON.

       

      I noticed that there is an undocumented annotation called "Key" that seems to make the job I need, so I wrote:

       

      @Portable
      public class MyDTO {

       

         private boolean stupid;

         @Key("STUPID_JSON_KEY_NAME")

         public boolean isStupid() {

         return stupid;
         }

       

         public void setStupid(boolean val) {

         this.stupid = val;
         }

      }

       

      but then when I try to deserialize it, nothing happen.

       

      I also noticed this code in the Errai generated code:

       

      if ((obj.containsKey("stupid")) && (!obj.get("stupid").isNull())) {

        entity.setStupid(java_lang_Boolean.demarshall(obj.get("stupid"), a1));
      }

      return entity;

      ...

      ...

      if (ref) {

        return json.append("}").toString();
      }

      return json.append(",").append("\"STUPID_JSON_KEY_NAME\":").append(java_lang_Boolean.marshall(a0.isStupid(), a1)).append(",").append("\"stupid\":").append(java_lang_Boolean.marshall(_$711591632__64711720_stupid(a0), a1)).append("}").toString();


      It seems that Key is used during writing, but not during reading phase, so I'm not able to deserialize the object.

       

      There are other strategies to reach my target (other than create a custom constructor with MapTo, because in that case I need to override all my properties and not only those with a stupid mapping).

       

      Thank you.

      L.