Error when trying to wrap an instance of JAXBElement



I have the following code,



JAXBContext jc = JAXBContext.newInstance(TestResults.class);
Marshaller m = jc.createMarshaller();
m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
OutputStream os = new FileOutputStream( "nosferatu.xml" );
TestResults tr = new TestResults();
tr.setUuid(new JAXBElement<String>(new QName("uuid"),String.class, "uuidcontent"));
//ObjectFactory objectFactory = new ObjectFactory();
m.marshal(new JAXBElement<TestResults>(new QName("uri","local"),TestResults.class,new TestResults()), System.out);


in which I am trying to wrap the Java String Class as a jaxb Element, since if I do not I get the


unable to marshal type “java.lang.String” error.


However when I try wrap the java.lang.string in a jaxb element, I get the following error


The method setUuid(String) in the type TestResults is not applicable for the arguments (JAXBElement<String>)


The setUuid method looks as follows



public void setUuid(java.lang.String value) {
this.uuid = value;
}


Why is is this error happening, and how can I fix this error?


No comments:

Post a Comment