I have a Gender enum (which I can't edit) which is used in a Java class. Now, when I need to Serialise the Java class to JSON, I want the value of the Enum as part of the JSON and not the Enum name. For example below in my enum, and when this enum is serialized, I want the value as {"gender":"Male"} I am using:
String underWritingJSONString = objectMapper.writeValueAsString(myObject);
public enum Gender {
MALE("Male"),
FEMALE("Female");
Gender(String gender) {
this.name = gender;
}
private String name;
String toValue() {
return name;
}
}
expected result = {"gender":"Male"}
current result = {"gender":"MALE"}
Following is the sample class
public class MyObject {
@JSONField
public Gender gender;
public MyObject() {
}
public Gender getGender() {
return this.gender;
}
}