, "flag2":<...">

Binding a JSON to a Java class using JAXB

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前端其它相关文章!

赞(0) 打赏
未经允许不得转载:web前端首页 » JavaScript 答疑

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

前端开发相关广告投放 更专业 更精准

联系我们

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏