I am building a spring boot application which accepts xml as input and produces xml as output. I can't use the spring boot default xml converter for parsing the input. I use jaxb library to parse them.
What I am doing is,
- I am generating java classes from xml schema(.xsd).
- Move the pojos as to spring boot application.
- Use the specific object as my input in my rest API's.
- Process the object and return the same object.
While returning the same object, I am not getting response as expected.
JAXBContext contextObj = JAXBContext.newInstance(Student.class);
Marshaller marshallerObj = contextObj.createMarshaller();
marshallerObj.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
marshallerObj.marshal(student, stringWriter);
return stringWriter.toString();
In order to get the expected result, I should have to change Response type as String and do the explicit marshalling. Is there any other way to rid of this?
Coming to the actual question, JAXB+Spring boot is the right way? or Steps which followed is correct?