Java XML JAXB Marshaller marshalObject(Object obj, File file)

Here you can find the source of marshalObject(Object obj, File file)

Description

marshal Object

License

Apache License

Declaration

public static void marshalObject(Object obj, File file) 

Method Source Code


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

import java.io.File;

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

public class Main {
    public static void marshalObject(Object obj, File file) {
        try {/*from   w  w w .ja  v a 2s  . c  o m*/
            JAXBContext jaxbContext = JAXBContext.newInstance("com.osafe.feeds.osafefeeds");
            Marshaller jaxbMarshaller = jaxbContext.createMarshaller();
            jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
            //jaxbMarshaller.setProperty(Marshaller.JAXB_ENCODING, "Unicode");
            jaxbMarshaller.marshal(obj, file);

        } catch (JAXBException e) {
            e.printStackTrace();
        }
    }

    public static void marshalObject(Object obj, String fileStr) {
        File file = new File(fileStr);
        marshalObject(obj, file);
    }
}

Related

  1. marshallObjectToXML(final Object jaxbModel, final URL schemaURL)
  2. marshallToString(Object jaxbElement, Class c)
  3. marshallToXml(String zpackage, Writer writer, Object data)
  4. marshallXml(final Object object)
  5. marshallXMLInConsole(Object obj)
  6. marshalObjectToXml(Object object, String xmlFilePath)
  7. marshalPackage(OutputStream printStream, final Package p)
  8. marshalToString(Object obj)
  9. marshalToString(Object obj)