How to manually map Enum fields in JAX-RS

后端 未结 2 963
遥遥无期
遥遥无期 2021-02-13 09:29

How can I map a simple JSON object {\"status\" : \"successful\"} automaticly map to my Java Enum within JAX-RS?

public enum Status {
    SUCESSFUL          


        
2条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-02-13 09:59

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

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

提交回复
热议问题