the goal is to force the override of the getter which returns a constant when I serialize. I search a solution on classes side, not on the serializer.
import lombok.Data;
import lombok.Getter;
import lombok.Setter;
import com.google.gson.Gson;
abstract class AbstractClass implements Serializable {
@Setter
@Getter
private String abstractVariable;
public abstract String getAbstractVariable();
}
@Data
class ConcreteClass extends AbstractClass implements Serializable {
private String concreteVariable;
@Override
public String getAbstractVariable() {
return "Constant Value";
}
}
Gson gson = new Gson();
System.out.println("ConcreteClass="+gson.toJson(new ConcreteClass()));
=>
ConcreteClass={}
This solution doesn't work, I tried many things without success: @Getter(AccessLevel.NONE) @Expose(serialize = false) ...