Java – how to manually map enumeration fields in jax-rs
•
Java
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
二维码