I have the following JSON, where can be either true or false:
{"flag1":, "flag2":}
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? JAXB supports JSON now? Or are you using a third-party library?
以上就是Binding a JSON to a Java class using JAXB的详细内容,更多请关注web前端其它相关文章!