How to use JAXBElement<String> in Web Service?

Viewed 72739

I am developing an interoperable web service using WCF which I am consuming from a Java client. When I created the proxy class it generated all the getter and setter methods as well as a JAXBElement<String> field. I searched for this in the JDK API and found the constructor:

JAXBElement(QName name, Class<T> declaredType, Class scope, T value) 

How should I use this constructor? Please explain the parameters and let me know if there is a good tutorial on the Internet describing its use.

8 Answers

I stumbled upon this question while I was looking for the same answer. I posted an answer but found a few problems. Here is a way to do it:

new javax.xml.bind.JAXBElement(
        new javax.xml.namespace.QName("http://locationOfURI", "nameOfElement"),
        javax.xml.bind.JAXBElement.class, 
        null, what your object's value is );

The last means the type parameter of JAXBElement.

Hope this works.

Related