title: How to use spring to marshal and unmarshal xml?
body: <p>I have a spring boot project. I have a few xsds in my project. I have generated the classes using maven-jaxb2-plugin. I have used <a href="http://www.davismol.net/2017/03/26/jaxb-marshalling-from-java-object-to-xml/" rel="noreferrer">this</a> tutorial to get a sample spring boot application running.</p>
  
  <pre><code>import org.kaushik.xsds.XOBJECT;
  
  @SpringBootApplication
  public class JaxbExample2Application {
  
  public static void main(String[] args) {
      //SpringApplication.run(JaxbExample2Application.class, args);
      XOBJECT xObject = new XOBJECT('a',1,2);
  
      try {
          JAXBContext jc = JAXBContext.newInstance(User.class);
  
          Marshaller marshaller = jc.createMarshaller();
          marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
          marshaller.marshal(xObject, System.out);
  
      } catch (PropertyException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
      } catch (JAXBException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
      }
   }
  }
  </code></pre>
  
  <p>But my concern is that I need to have all the jaxb classes of the schema mapped. Also is there something in Spring that I can use to make my task easier. I have looked at the Spring <a href="http://docs.spring.io/spring-ws/site/reference/html/oxm.html" rel="noreferrer">OXM</a> project but it had application context configured in xml. Does spring boot have anything that I can use out of the box. Any examples will be helpful.</p>
  
  <p><strong>Edit</strong></p>
  
  <p>I tried <a href="https://stackoverflow.com/questions/44676532/how-to-use-spring-to-marshal-and-unmarshal-xml/44678803#44678803">xerx593's answer</a> and I ran a simple test using main method </p>
  
  <pre><code>    JaxbHelper jaxbHelper = new JaxbHelper();
      Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
      marshaller.setClassesToBeBound(XOBJECT.class);
      jaxbHelper.setMarshaller(marshaller);
      XOBJECT xOBJECT= (PurchaseOrder)jaxbHelper.load(new StreamSource(new FileInputStream("src/main/resources/PurchaseOrder.xml")));
      System.out.println(xOBJECT.getShipTo().getName());
  </code></pre>
  
  <p>It ran perfectly fine. Now I just need to plug it in using spring boot.</p>