code: public static String obj2Xml(Class clazz, Object o)  throws JAXBException, ParserConfigurationException {
          Document doc = obj2Doc(clazz, o);
  
          DOMImplementationLS domImplementation = (DOMImplementationLS) doc.getImplementation();
          LSSerializer lsSerializer = domImplementation.createLSSerializer();
          DOMConfiguration domConfiguration = lsSerializer.getDomConfig();
          if (domConfiguration.canSetParameter("format-pretty-print", Boolean.TRUE)) {
              lsSerializer.getDomConfig().setParameter("format-pretty-print", Boolean.TRUE);
          }
          lsSerializer.setNewLine("\n");
  
          try {
              // Encode as UTF-8
              ByteArrayOutputStream baos = new ByteArrayOutputStream();
              LSOutput lsOutput = domImplementation.createLSOutput();
              lsOutput.setEncoding("UTF-8");
              lsOutput.setByteStream(baos);
              lsSerializer.write(doc, lsOutput);
  
              return baos.toString("UTF-8");
          }
          catch (UnsupportedEncodingException uee) {
              return lsSerializer.writeToString(doc); // Produces UTF-16
          }
      }
docs: Serializes an object into XML
  <p>
  You need to catch the JAXBException, but beware that the cause is not conveyed correctly through getCause().
  Take a peek at the internal 'cause' member and look out for detailed information about the problem.
  
  com.sun.xml.internal.bind.v2.runtime.IllegalAnnotationsException: 2 counts of IllegalAnnotationExceptions
  x.y.A does not have a no-arg default constructor.
  this problem is related to the following location:
  at x.y.A
  at public java.util.Collection x.y.A.getEntries()
  at x.y.Z
  x.y.B does not have a no-arg default constructor.
  this problem is related to the following location:
  at x.y.B
  at public java.util.Collection x.y.A.getEntries()
  at x.y.A
  at public java.util.Collection x.y.Z.getEntries()
  at x.y.Z
  
  You need to take a peek at 'cause' in a debugger when initially developing the application.