Java XML JAXB Serialize serialize(Object object, Class clazz, String filename)

Here you can find the source of serialize(Object object, Class clazz, String filename)

Description

serialize

License

LGPL

Declaration

public static <T> void serialize(Object object, Class<T> clazz, String filename) throws JAXBException 

Method Source Code


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

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

public class Main {
    public static <T> void serialize(Object object, Class<T> clazz, String filename) throws JAXBException {
        JAXBContext context = JAXBContext.newInstance(clazz);
        Marshaller m = context.createMarshaller();
        m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
        m.marshal(object, new File(filename));
    }/*from w ww.  j  av a2 s . c o  m*/
}

Related

  1. serialize(JAXBElement object)
  2. serialize(Object o, OutputStream os, Boolean format)
  3. serialize(Object o, OutputStream os, Boolean format)
  4. serialize(Object obj)
  5. serialize(Object obj)
  6. serialize(T object, Class objectClass, OutputStream resultStream)
  7. serialize(T object, Path path)
  8. serializeFile(String path, Object o)
  9. serializeToFile(Class clazz, T object, String outputFile)