title: Convert java object to XML REST response
body: <p>I want to return XML response message after API REST call. I tried this simple test:</p>
  
  <pre><code>@RestController
  public class HelloWorldRestController {
  
      @Autowired
      ApiService apiService;
      @RequestMapping(value = "/api", method = RequestMethod.GET)
          public ResponseEntity&lt;VisaResponse&gt; listAllUsers() {
              VisaResponse obj = apiService.visaresponse();
              return new ResponseEntity&lt;VisaResponse&gt;(obj, HttpStatus.OK);
          }
      .......
  }
  </code></pre>
  
  <p>I tried to convert simple object to XML</p>
  
  <pre><code>public class VisaResponse {
  
      public VisaResponse() {
          jaxbObjectToXML(new VisaResponseHeader());
      }
  
      private static String jaxbObjectToXML(VisaResponseHeader customer) {
          String xmlString = "";
          try {
              JAXBContext context = JAXBContext.newInstance(VisaResponseHeader.class);
              Marshaller m = context.createMarshaller();
  
              m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); // To format XML
  
              StringWriter sw = new StringWriter();
              m.marshal(customer, sw);
              xmlString = sw.toString();
  
          } catch (JAXBException e) {
              e.printStackTrace();
          }
          return xmlString;
      }
  }
  
  public class VisaResponseHeader {
  
      private int id;
  
      public VisaResponseHeader() {
          id = 3;
      }   
  }
  </code></pre>
  
  <p>But when I make a rest request nothing happens - no any response. Do you have any idea where I'm wrong? Simple content should be returned.</p>