Java XML JAXB Object to XML writeJaxbObject(OutputStream outputStream, JAXBElement jaxbElement, Class modelClass)

Here you can find the source of writeJaxbObject(OutputStream outputStream, JAXBElement jaxbElement, Class modelClass)

Description

write Jaxb Object

License

Open Source License

Parameter

Parameter Description
outputStream a parameter
jaxbElement a parameter
modelClass a parameter

Exception

Parameter Description
JAXBException an exception

Declaration

public static void writeJaxbObject(OutputStream outputStream, JAXBElement<?> jaxbElement, Class<?> modelClass)
        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.JAXBElement;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;

public class Main {
    /**/*from   w  w w .j  ava 2s  .  co m*/
     * 
     * @param outputStream
     * @param jaxbElement
     * @param modelClass
     * @throws JAXBException
     */
    public static void writeJaxbObject(OutputStream outputStream, JAXBElement<?> jaxbElement, Class<?> modelClass)
            throws JAXBException {
        JAXBContext context = JAXBContext.newInstance(modelClass.getPackage().getName());
        Marshaller marshaller = context.createMarshaller();
        marshaller.setProperty(Marshaller.JAXB_ENCODING, "UTF-8");
        marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
        marshaller.marshal(jaxbElement, outputStream);
    }
}

Related

  1. toXMLString(final T binding)
  2. toXMLString(Object obj)
  3. toXmlString(T obj, Class type)
  4. write(Object jaxbAnnotatedObj, OutputStream os)
  5. write(String filepath, T content, Class typeParameterClass)
  6. xmlEntityToString(final T entity)
  7. XmlObjectToString(Object o)