How to manually map Enum fields in JAX-RS How to manually map Enum fields in JAX-RS json json

How to manually map Enum fields in JAX-RS


The following JAXB annotations should do it. (I tested using Jettison but I've not tried other providers):

@XmlType(name = "status")@XmlEnumpublic enum Status {    @XmlEnumValue(value = "successful")    SUCESSFUL,     @XmlEnumValue(value = "error")    ERROR;}


This might help you

@Entitypublic class Process {  private State state;  public enum State {    RUNNING("running"), STOPPED("stopped"), PAUSED("paused");    private String value;    private State(String value) {      this.value = value;    }    @JsonValue    public String getValue() {      return this.value;    }    @JsonCreator    public static State create(String val) {      State[] states = State.values();      for (State state : states) {        if (state.getValue().equalsIgnoreCase(val)) {          return state;        }      }      return STOPPED;    }  }}