The JAX-RS web service I’m calling is throwing xml content as text/html content type. On my side, I need to read the xml, and convert it to Java object.
The problem is: the response xml isn’t formatted right and has newline characters in wrong places, such as – there are several newline characters before <?xml version="1.0" encoding="UTF-8"?> . This is causing problems trying to unmarshall it.
Is there a way I can unmarshall the response xml string though it has formatting problems?
Thanks in advance.
HttpGet httpGet = new HttpGet(uri);
HttpResponse response = client.execute(httpGet);
InputStream inputStream = response.getEntity().getContent();
JAXBContext context = JAXBContext.newInstance(MyClass.class);
MyClass myObj = (MyClass) context.createUnmarshaller().unmarshal(inputStream);
Finally got the provider to send the response in xml/application format. However, as a way out, an option that I found is to save the content as a file, and then again retrieve content from the file.