Java XML JAXB Marshaller marshal(T object)

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

Description

marshal

License

Open Source License

Declaration

@SuppressWarnings("unchecked")
    public static <T> String marshal(T object) throws IOException, JAXBException 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.io.ByteArrayOutputStream;
import java.io.IOException;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;

public class Main {
    @SuppressWarnings("unchecked")
    public static <T> String marshal(T object) throws IOException, JAXBException {
        Class<T> clzz = (Class<T>) object.getClass();
        JAXBContext context;//from  w  ww. ja va 2  s . c o  m
        context = JAXBContext.newInstance(clzz);
        Marshaller m = context.createMarshaller();
        ByteArrayOutputStream os = new ByteArrayOutputStream();
        m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
        m.marshal(object, os);
        return os.toString();
    }
}

Related

  1. marshal(Object object, OutputStream stream)
  2. marshal(Object objectToMarshal)
  3. marshal(Object source, Class configurationClass)
  4. marshal(T bean, Class... bc)
  5. marshal(T clazz)
  6. marshal(T t, Class entityClass)
  7. marshalAsString(Class clz, T marshalObj)
  8. marshall(Class c, String xml)
  9. marshall(final Object o, Class clazz)