Java XML JAXB Marshaller marshal(Object obj)

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

Description

marshal

License

Apache License

Declaration

public static String marshal(Object obj) throws JAXBException 

Method Source Code


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

import javax.xml.bind.*;

import java.io.StringWriter;

public class Main {
    public static String marshal(Object obj) throws JAXBException {
        return marshal(obj, obj.getClass());
    }// w w  w .ja  v  a 2  s  . c om

    private static <T> String marshal(Object obj, Class<T> contextClass) throws JAXBException {
        final JAXBContext context = JAXBContext.newInstance(contextClass);
        final Marshaller marshaller = context.createMarshaller();
        final StringWriter stringWriter = new StringWriter();
        marshaller.marshal(obj, stringWriter);
        final String output = stringWriter.toString();
        return output;
    }
}

Related

  1. marshal(Marshaller marshaller, Object object, String filename)
  2. marshal(Marshaller marshaller, Object object, String filename)
  3. marshal(Object bean)
  4. marshal(Object entity)
  5. marshal(Object obj)
  6. marshal(Object obj)
  7. marshal(Object obj, Class clazz)
  8. marshal(Object obj, OutputStream out)
  9. marshal(Object obj, OutputStream out, Class... boundClasses)