Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

XmlElement annotation dissallowed with WebParam

I have a method inside a webservice, with the following signature:

@WebResult(name="purchaseId") public int CreatePurchase(
            @XmlElement(required=true)
            @WebParam(name = "item") String item {
  ...
}

It seems to me (based on what information i've found) that this should work. Unfortunately, I get the following error message on compilation:

The annotation @XmlElement is disallowed for this location

Does anyone know how to resolve the issue?

like image 556
MW. Avatar asked Nov 21 '11 11:11

MW.


2 Answers

JAX-B is included with a JDK by default. The version that comes with the particular JDK isn't updated nearly as frequently as JAX-B itself. The current version that comes with the JDK (1.6) is JAX-B 2.1.10 (documented here).

@XmlElement is only allowed on method parameters starting with JAX-B 2.2

When Java loads libaries it loads libraries that come with the JDK before it loads libraries that are on the classpath. Upgrdading to Java 7 would fix your problem. There is also a process for telling Java that you want to use a more up-to-date library if you aren't able to upgrade to Java 7. These are called "endorsed" libraries and you have to put the library in the same folder structure as the JDK itself. The process is described here.

like image 170
Pace Avatar answered Nov 20 '22 12:11

Pace


When you are having the following error message: "The annotation @XmlElement is disallowed for this location", chances are that you're using the wrong import statement.

Change it to:

import javax.xml.bind.annotation.XmlElement;

As Eclipse suggests another package as the first option, it's a very common mistake.

like image 39
Thiago Pasa Avatar answered Nov 20 '22 11:11

Thiago Pasa