How to manually map Enum fields in JAX-RS

后端 未结 2 1015
心在旅途
心在旅途 2021-02-13 09:07

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

public enum Status {
    SUCESSFUL          


        
2条回答
  •  Happy的楠姐
    2021-02-13 09:58

    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;
    }
    

提交回复
热议问题