JAXB “Class has two properties of the same name” issue

Using the JAX-WS RI, if you want to annotate a field as “required” (for example), you can use the following annotation:

 

When I added this before a field in a class, e.g.:

 

and then ran wsgen to generate the web service, it would always fail with

Caused by: com.sun.xml.bind.v2.runtime.IllegalAnnotationsException:
1 counts of IllegalAnnotationExceptions


Class has two properties of the same name "action"However, if you move the annotation to the getter method, e.g.

it works fine.

 

I came across this issue when using the JAX-WS RI, and there’s been some discussion about it on the web. The answer is detailed on this page (if you can get to it, some of those sun.com sites (incuding, annoyingly, jax-ws.dev.java.net) seem to be down or not available a lot of the time! I ended up just looking at the Google cached text of the page…).

 

In short, the answer is that unless you specify it, the XmlAccessorType will default to PUBLIC_MEMBER, which will cause JAXB to bind public fields and public getter/setters. So a private instance variable won’t be bound unless you change the default using @XmlAccessorType(XmlAccessType.FIELD) on the class. Not sure if I understand the message though - how come wsgen reports two properties with the same name in this case? - but this is a workaround anyway.

  • 0
    点赞
  • 0
    收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
©️2022 CSDN 皮肤主题:大白 设计师:CSDN官方博客 返回首页
评论 1
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值