Search code examples
google-app-engineobjectifyauto-value

Objectify with Google AutoValue


I want to use auto value with objectify model entity. Objectify requires @Id annotation with a field value however in Google AutoValue all fields need to be converted to abstract methods, so I can't apply @Id to a abstract method. What is your suggestions?

@Entity
@Cache
@AutoValue
public abstract class AccountDetail {

    // Objectify needs this
    @Id
    private long id;

    // auto value needs this
    abstract long id();
}

Solution

  • I'm not familiar with AutoValue, but it doesn't look possible. Objectify works with real fields on real classes. You'd need some way of forcing the tool to generate code with the relevant annotations.

    Have you considered lombok? It is an elegant way of avoiding a lot of Java's boilerplate and doesn't require code generation.