How to set values in Enum?

0

Watch Grid

TherecordthatiscomingfromthedatabaseisofanEnumclass,thecorrectonewasfortheresultinthegridtobeprintednamevalueandnotV.

ThisisEnum;

VALOR("V", "Valor"),
    PERCENTUAL("P", "Percentual"),
    DIA("D", "Dia"),
    HORA("H", "Hora");

I'd rather treat this Back-End problem than in Front-End, the enum class is created as shown below because it will also be loaded into other parts of the system as listBox, my idea would be when the value comes as V was set automatically as Value, when P was set automatically as Percentage, and so on.

public enum EventoTipoMultiplicador implements EnumConverter<EventoTipoMultiplicador, String> {

    VALOR("V", "Valor"),
    PERCENTUAL("P", "Percentual"),
    DIA("D", "Dia"),
    HORA("H", "Hora");

    private final String codigo;
    private final String descricao;

    public static final EnumValues<EventoTipoMultiplicador, String> VALORES = EnumUtils
            .getEnumValuesMap(EventoTipoMultiplicador.class);

    EventoTipoMultiplicador(String codigo, String descricao) {
        this.codigo = codigo;
        this.descricao = descricao;
    }

    @Override
    @JsonValue
    public String getValue() {
        return codigo;
    }

    public String getDescricao() {
        return descricao;
    }



    @JsonCreator
    public static EventoTipoMultiplicador fromValue(String v) {
        return EventoTipoMultiplicador.VALORES.getEnum(v);
    }

}

These changes can be made here in this method below;

   @JsonCreator
    public static EventoTipoMultiplicador fromValue(String v) {
        return EventoTipoMultiplicador.VALORES.getEnum(v);
    }

When loading the GRID it shows the following result with the STS debug.

The problem is that I do not know how to make change in the method due to lack of experience.

    
asked by anonymous 11.12.2018 / 15:02

1 answer

1
return EventoTipoMultiplicador.VALORES.getEnum(v).getDescricao();

OU

Change the toString() of the enumerated to give return of the attribute descricao .

@Override
    public String toString() {
        return descricao;
    }

And when you want to search for the description just do enumerado.toString()

    
15.12.2018 / 01:24