Objectify with Cloud Endpoints

后端 未结 4 804
暖寄归人
暖寄归人 2021-02-01 22:17

I am using appengine cloud endpoints and objectify. I have previously deployed these endpoints before and now I am updating them and it is not working with Objectify. I have m

4条回答
  •  闹比i
    闹比i (楼主)
    2021-02-01 22:54

    At first, I did not understand the answer given by Flori, and how useful it really is. Because others may benefit, I will give a short explanation.

    As explained earlier, you can use @ApiTransformer to define a transformer for your class. This would transform an unserializable field, like those of type Key into something else, like a Long.

    It turns out that when a class is processed by GCE, methods called get{fieldName} and set{FieldName} are automatically used to transform the field {fieldName}. I have not been able to find this anywhere in Google's documentation.

    Here is how I use it for the Key{Machine} property in my Exercise class:

    public class Exercise {
      @ApiResourceProperty(ignored = AnnotationBoolean.TRUE)
      public Key machine;
      // ... more properties
    
      public Long getMachineId() {
        return this.machine.getId();
      }
    
      public void setMachineId(Long machineId) {
        this.machine = new Key(Machine.class, machineId);
      }
    
      // ...
    }
    

提交回复
热议问题