Java XML JAXB Marshaller marshal(Object obj, OutputStream out)

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

Description

marshal

License

Open Source License

Declaration

public static void marshal(Object obj, OutputStream out) 

Method Source Code


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

import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;
import java.io.*;

public class Main {
    public static void marshal(Object obj, OutputStream out) {
        try {//from  www  .j  a  v a  2  s .c om
            JAXBContext context = JAXBContext.newInstance(obj.getClass());
            Marshaller marshaller = context.createMarshaller();
            marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
            marshaller.marshal(obj, out);
        } catch (JAXBException e) {
            throw new RuntimeException(e);
        }

    }

    public static void marshal(Object obj, Writer writer) {
        try {
            JAXBContext context = JAXBContext.newInstance(obj.getClass());
            Marshaller marshaller = context.createMarshaller();
            marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
            marshaller.marshal(obj, writer);
        } catch (JAXBException e) {
            throw new RuntimeException(e);
        }

    }
}

Related

  1. marshal(Object entity)
  2. marshal(Object obj)
  3. marshal(Object obj)
  4. marshal(Object obj)
  5. marshal(Object obj, Class clazz)
  6. marshal(Object obj, OutputStream out, Class... boundClasses)
  7. marshal(Object obj, OutputStream stream)
  8. marshal(Object object)
  9. marshal(Object object)