Java XML JAXB Marshaller marshal(final Object object)

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

Description

marshal

License

Open Source License

Declaration

public static String marshal(final Object object) 

Method Source Code

//package com.java2s;
//License from project: Open Source 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(final Object object) {
        try {//from  ww  w . j a v a2 s  . com
            final JAXBContext context = JAXBContext.newInstance(object.getClass());
            final Marshaller marshaller = context.createMarshaller();
            marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
            final StringWriter out = new StringWriter();
            marshaller.marshal(object, out);
            return out.toString();
        } catch (JAXBException e) {
            e.printStackTrace();
            return null;
        }
    }
}

Related

  1. marshal(Class c, String xml)
  2. marshal(Class c, String xml)
  3. marshal(Class clazz, T obj)
  4. marshal(Class clazz, T object)
  5. marshal(final Object obj, final Class... classes)
  6. marshal(final Object object)
  7. marshal(JAXBContext context, Object object, Writer writer, Map properties)
  8. marshal(JAXBElement e, File f)
  9. marshal(JAXBElement jaxbElement, Class cls)