Java XML JAXB Marshaller marshal(Object object)

Here you can find the source of marshal(Object object)

Description

marshal

License

Apache License

Declaration

public static String marshal(Object object) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.io.StringWriter;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;

public class Main {
    public static String marshal(Object object) {
        try {/*from   w  ww  .j a v  a  2 s. c  om*/
            StringWriter writer = new StringWriter();
            JAXBContext jaxbContext = JAXBContext.newInstance(object.getClass());

            Marshaller marshaller = jaxbContext.createMarshaller();
            marshaller.marshal(object, writer);

            return writer.toString();
        } catch (JAXBException e) {
            throw new RuntimeException("Error marshalling object", e);
        }
    }
}

Related

  1. marshal(Object obj, Class clazz)
  2. marshal(Object obj, OutputStream out)
  3. marshal(Object obj, OutputStream out, Class... boundClasses)
  4. marshal(Object obj, OutputStream stream)
  5. marshal(Object object)
  6. marshal(Object object)
  7. marshal(Object object, File file, JAXBContext ctx)
  8. marshal(Object object, OutputStream stream)
  9. marshal(Object objectToMarshal)