Java XML JAXB Object to XML write(Object jaxbAnnotatedObj, OutputStream os)

Here you can find the source of write(Object jaxbAnnotatedObj, OutputStream os)

Description

write

License

Open Source License

Declaration

public static void write(Object jaxbAnnotatedObj, OutputStream os) throws JAXBException 

Method Source Code

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

import java.io.OutputStream;

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

public class Main {
    public static void write(Object jaxbAnnotatedObj, OutputStream os) throws JAXBException {
        JAXBContext context = JAXBContext.newInstance(jaxbAnnotatedObj.getClass());
        Marshaller marshaller = context.createMarshaller();
        marshaller.setProperty(Marshaller.JAXB_FRAGMENT, true);
        marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
        marshaller.marshal(jaxbAnnotatedObj, os);
    }/*www.j a va2s.c o m*/

    public static void write(Object jaxbAnnotatedObj, OutputStream os, boolean outputAsFragment)
            throws JAXBException {
        JAXBContext context = JAXBContext.newInstance(jaxbAnnotatedObj.getClass());
        Marshaller marshaller = context.createMarshaller();
        marshaller.setProperty(Marshaller.JAXB_FRAGMENT, outputAsFragment);
        marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
        marshaller.marshal(jaxbAnnotatedObj, os);
    }
}

Related

  1. toXml(T element)
  2. toXml(T object)
  3. toXMLString(final T binding)
  4. toXMLString(Object obj)
  5. toXmlString(T obj, Class type)
  6. write(String filepath, T content, Class typeParameterClass)
  7. writeJaxbObject(OutputStream outputStream, JAXBElement jaxbElement, Class modelClass)
  8. xmlEntityToString(final T entity)
  9. XmlObjectToString(Object o)