I want to return the attribute value
as the default return type. I'm trying to avoid having my own getter & then storing the return value as an int
in some object.
Ideally, some simple annotation to achieve this would be most convenient. Is there any form of @JsonFormat
I might be able to use? I believe @Enumerated
is just for persistence & only supports String & Ordinal anyways.
public enum Rank {
NONE(-1)
PRIVATE(1)
CAPTAIN(2)
GENERAL(3)
private int value;
Rank(int value) { this.value = value; }
}
class RankDto {
private String id;
private Rank rank;
}
EDIT: After some digging I found out that using @JsonValue
annotation on the field or on its getter method will result in that value by used for serialization/deserialization. The DB persisted value will not be affected.