HTTP Put Enum using JAX-RS REST-Service HTTP Put Enum using JAX-RS REST-Service json json

HTTP Put Enum using JAX-RS REST-Service


@XmlEnumValue annotation declares which string value is mapped to annotated enum constant. i.e. when you write

@XmlEnumValue(value = "lov.account.type.customer")CUSTOMER("lov.account.type.customer")

then CUSTOMER constant is mapped to lov.account.type.customer string.

So if you want that CUSTOMER constant is mapped to CUSTOMER string then you need to write

@XmlEnumValue(value = "CUSTOMER")CUSTOMER("lov.account.type.customer")

or remove @XmlEnumValue annotation i.e.

@XmlEnumpublic enum AccountType implements TranslatableEnum {    CUSTOMER("lov.account.type.customer"),    AGENT("lov.account.type.agent")    //...}


UPDNow I see that root of the problem is inheritance. If you try to deserialize an inherited class EclipseLink by default uses @type field to determine which class should be instantiated for which input. See this answer. So you have several ways to go depending on your circumstances.

First way (dirty enough)
You can try to annotate your supertype with @XmlDiscriminatorNode("fakeField") It is applicable only if you have one child class

Second way
If you have exact relation between AccountType constant and child class you need to annotate each child class with @XmlDiscriminatorValue annotation.
Example:

@XmlRootElementpublic static class Parent {    AccountType type;    public AccountType getType() {        return type;    }    public void setType(AccountType type) {        this.type = type;    }}@XmlDiscriminatorValue("AGENT")public static class Agent extends Parent {}@XmlDiscriminatorValue("CUSTOMER")public static class Customer extends Parent {}


It's not exactly the same scenario, but I had a similar problem in Jersey using JSON and Enums.

One thing I see in your enum definition is that you specify a custom name for the enum

AGENT("lov.account.type.agent")

But it seems you're sending AGENT in the JSON data. Shouldn't you be sending 'lov.account.type.agent' instead?