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.

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值