Ok, I’ve searched everywhere for an answer to this. It is driving me nuts.
All I need to do is unmarshal a very simple webservice response. The only problem is, I am using a generated source file without the @XmlRootElement annotation. I am unable to edit this generated source file to add @XmlRootElement, either. I need to use it “as is”.
This is the current code that I have, but it is resulting in an error shown at the bottom of this post. I have tried to use a JAXBElement wrapper but to no avail. Could somebody please give me the code I need? I have no idea how to use "QName"s etc.
This code below works great with classes that have @XmlRootElement:
MyGeneratedClass response = restTemplate.getForObject("url to webservice!"),
MyGeneratedClass.class);
return response
Sadly, it is producing this error in this case. Please help me to unmarshal the REST response!
Could not extract response: no suitable HttpMessageConverter found for response
type [MyGeneratedClass] and content type [application/xml;version=1]
I forgot about posting this many months ago and I should probably follow it up with the solution.
This solution also adds a cookie to the request headers, but you can ignore that.
In the case that a generated source file does not have @XmlRootElement annotation, you can unmarshal as follows: