Java XML JAXB Serialize save(File file, T obj, Class... clazz)

Here you can find the source of save(File file, T obj, Class... clazz)

Description

save

License

Open Source License

Declaration

public static <T> void save(File file, T obj, Class<?>... clazz) throws JAXBException 

Method Source Code


//package com.java2s;
//License from project: Open Source 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 <T> void save(File file, T obj, Class<?>... clazz) throws JAXBException {
        //Create JAXB Context
        JAXBContext jc = JAXBContext.newInstance(clazz);
        //Create marshaller
        Marshaller marshaller = jc.createMarshaller();
        marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);

        marshaller.marshal(obj, file);//  w  ww  .  j  a va2  s .c o m
    }
}

Related

  1. deserialize(String data, String className)
  2. deserializeFile(String path, Class clazz)
  3. deserializeFromXmlFile(T defaultObject, String fileName)
  4. deserializeXmlToJava(String valueType, Serializable value)
  5. save(Class confClass, Object confObj, File xmlFile)
  6. saveDataToFile(File file, T data)
  7. saveModel(JAXBElement model, String packageName)
  8. saveObject(Path path, T object)
  9. saveObject(T object, Class typeClass, URL path)