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.
Code example extracted from Stack Overflow: ObjectFactory factory = new ObjectFactory(); JAXBElement<String> createMessageDescription = factory. createMessageDescription("description"); message. setDescription(createMessageDescription);
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() .
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);
ObjectFactory fact = new ObjectFactory();
JAXBElement<String> str = fact.createCompositeTypeStringValue("vik");
comp.setStringValue(str);
CompositeType retcomp = service.getDataUsingDataContract(comp);
System.out.println(retcomp.getStringValue().getValue());
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);
Other alternative:
JAXBElement<String> element = new JAXBElement<>(new QName("Your localPart"),
String.class, "Your message");
Then:
System.out.println(element.getValue()); // Result: Your message
I don't know why you think there's no constructor. See the API.
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