1

This is my enum class:

@XmlType(name = "V4NetworkCIDRType")
@XmlEnum
public enum V4NetworkCIDRType {
    @XmlEnumValue("Y")
    Y("Y"),
    @XmlEnumValue("N")
    N("N");

    private final String value;

    V4NetworkCIDRType(String v) {
        value = v;
    }

    public String value() {
        return name();
    }

    public static V4NetworkCIDRType fromValue(String v) {
        for (V4NetworkCIDRType c: V4NetworkCIDRType.values()) {
            if (c.value.equals(v)) {
                return c;
            }
        }
        throw new IllegalArgumentException(v);
    }
}

I have a field with name cird and type is V4NetworkCIDRType. If I set value for cird is Y or N, it working correctly. But when I send a request JSON format with wrong cidr value:

{
    "cidr": "@"
}

It will return 400 Bad request

But when I send request with XML format:

 <cidr>@</cidr>

It's OK.

How I can do that with JSON format?

Tam Nguyen
  • 93
  • 1
  • 3
  • 11

0 Answers0