How to GET Mapped ENUM Values in JSON using REST API

I hit entity in which one attribute is mapped as ENUM for that attribute JSON should return their value instead of name specify in ENUM class

You can create a separate method annotated with the MetaProperty annotation in your entity. After that in JSON you’ll be able to get the plain enum value.

Suppose, you have a enum:

public enum Gender implements EnumClass<String> {

    MALE("M"),
    FEMALE("F");

    private String id;

    Gender(String value) {
        this.id = value;
    }

    public String getId() {
        return id;
    }

    @Nullable
    public static Gender fromId(String id) {
        for (Gender at : Gender.values()) {
            if (at.getId().equals(id)) {
                return at;
            }
        }
        return null;
    }
}

The class that uses the enum:

@NamePattern("%s|name")
@Table(name = "FILTERCAPTION_EMPLOYEE")
@Entity(name = "filtercaption$Employee")
public class Employee extends StandardEntity {
    private static final long serialVersionUID = -2211979749197500001L;

    @Column(name = "NAME")
    protected String name;

    @Column(name = "GENDER")
    protected String gender;

    public void setName(String name) {
        this.name = name;
    }

    public String getName() {
        return name;
    }

    public void setGender(Gender gender) {
        this.gender = gender == null ? null : gender.getId();
    }

    public Gender getGender() {
        return gender == null ? null : Gender.fromId(gender);
    }

    @MetaProperty
    public String getPlainGenderValue() {
        return gender;
    }
}

As you see there is a getPlainGenderValue() method in the class that returns an enum value. In the JSON you’ll have the plainGenderValue attribute:

    {
        "_entityName": "demo$Employee",
        "_instanceName": "Alice",
        "id": "5c1df6f9-4535-a19c-5698-e0d6d2c12e54",
        "gender": "FEMALE",
        "name": "Alice",
        "version": 1,
        "plainGenderValue": "F"
    }

Thank You for your support