Java – how to manually map enumeration fields in jax-rs

How to map a simple JSON object {"status": "successful"} to Java enum in jax-rs automatically?

public enum Status {
    SUCESSFUL ("successful"),ERROR ("error");

    private String status;

    private Status(String status) {
        this.status = status;
    }
}

If you need more details, please feel free to ask:)

Solution

The following JAXB annotations should do this (I use jettison for testing, but I haven't tried other providers):

@XmlType(name = "status")
@XmlEnum
public enum Status {
    @XmlEnumValue(value = "successful")
    SUCESSFUL,@XmlEnumValue(value = "error")
    ERROR;
}
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>