I have a simple enum that has to properties, OK and FAULT. I am trying to return the value in lowercase when returning it as a Json Object by using the @JsonProperty annotation. First I thought that because I was mixing java.xmlbind.annotation with com.fasterxml was the problem, but after removing the java.xmlbind it still does not work.
The Object that uses this enum always shows either OK or FAULT with json requests, and not ok and fault as it does when requesting XML.
Using Jackson 2.5.x
Any insights or suggestions will be greatly appreciated.
import javax.xml.bind.annotation.XmlEnum;
import javax.xml.bind.annotation.XmlEnumValue;
import com.fasterxml.jackson.annotation.JsonProperty;
/**
*
*/
@XmlEnum
public enum RequestStatusType {
/**
* Generic server A-OK ;)
*/
@XmlEnumValue(value="ok")
@JsonProperty(value="ok")
OK,
/**
* Generic unknown server fault
*/
@XmlEnumValue(value="fault")
@JsonProperty(value="fault")
FAULT;
/**
* Returns a RequestStatusType based on the string passed in
* @param requestStatusType the requestStatusType to get
*/
public static RequestStatusType getRequestStatus (String requestStatusTypeStr) {
try {
return valueOf( requestStatusTypeStr.toUpperCase() );
} catch (Exception e) {
return null;
}
}
/* (non-Javadoc)
* @see java.lang.Enum#toString()
*/
@Override
public String toString() {
return super.toString().toLowerCase();
}
}
You need check your Jackson version. Your way only works with Jackson 2.7.2 or newer. Please refer to When is the @JsonProperty property used and what is it used for? . Hope can help.