I have the following JSON, where can be either true or false:
{"flag1":<boolean value>, "flag2":<boolean value>}
And I have tried to bind it to a Java class using Jersey and the following JAXB annotations:
@XmlRootElement
public class MyClass {
@XmlElement(name = "flag1", type = Boolean.class)
private Boolean flag1;
@XmlElement(name = "flag2", type = Boolean.class)
private Boolean flag2;
...
}
The problem is that when I assign a non-boolean value to 'flag1' or 'flag2', like in the example below, JAXB automatically assigns a false value to the 'flag1' and 'flag2' fields of MyClass.
{"flag1":"foo", "flag2":"bar"}
Is there a way to annotate 'MyClass' so that when JSON's 'flag1' and 'flag2' are not boolean I get an exception?