How do I instantiate a JAXBElement<String> object?
JavaJaxbJava Problem Overview
I need to create one of these as the interface requires it. Can someone please let me know how to create one, as there doesn't seem to be a c'tor defined?
Java Solutions
Solution 1 - Java
When you imported the WSDL, you should have an ObjectFactory
class which should have bunch of methods for creating various input parameters.
ObjectFactory factory = new ObjectFactory();
JAXBElement<String> createMessageDescription = factory.createMessageDescription("description");
message.setDescription(createMessageDescription);
Solution 2 - Java
ObjectFactory fact = new ObjectFactory();
JAXBElement<String> str = fact.createCompositeTypeStringValue("vik");
comp.setStringValue(str);
CompositeType retcomp = service.getDataUsingDataContract(comp);
System.out.println(retcomp.getStringValue().getValue());
Solution 3 - Java
Here is how I do it. You will need to get the namespace URL and the element name from your generated code.
new JAXBElement(new QName("http://www.novell.com/role/service","userDN"),
new String("").getClass(),testDN);
Solution 4 - Java
Other alternative:
JAXBElement<String> element = new JAXBElement<>(new QName("Your localPart"),
String.class, "Your message");
Then:
System.out.println(element.getValue()); // Result: Your message
Solution 5 - Java
I don't know why you think there's no constructor. See http://java.sun.com/javase/6/docs/api/javax/xml/bind/JAXBElement.html#JAXBElement(javax.xml.namespace.QName,%20java.lang.Class,%20T)">the API.