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.
You can do the following: JAXBElement<String> jaxbElement = new JAXBElement(new QName("http://mycompany/services", "amount"), String. class, "Hello World"); There should also be a create method on the generated ObjectFactory class that will create this instance of JAXBElement with the appropriate info for you.
1 Answer. Show activity on this post. If getProject() returns the type JAXBElement<String> then getName() returns the name of the XML tag. To get the value of that element you need to call getValue() .
JAXBElement is used to preserve the element name/namespace in use cases where enough information is not present in the object model. It's often used with substitution groups. Without any JAXB metada the result will be wrapped in a JAXBElement.
QName getName() This method returns the xml element tag name. 3. Class getScope() This method returns scope of xml element declaration.
A solution this problem is, you do not need to create a seperate constructor for creating a JAXBElement
. The respected element can be retrieved from objectFactory.create........()
method. Suppose you want to create and set some value in response object, and argument is as of JAXBElement
type, then you need to do this way:
someResponseObj.setMyValue(objectFactory.create.......()); /*method name that will be return a JAXBElement in setter()*/
Note: Please check the ObjectFactory
reference because there can be multiple ObjectFactory
classes in generated code so you need to refer the exact one which is associated to the class of that package.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With