Java XML JAXB Serialize saveModel(JAXBElement model, String packageName)

Here you can find the source of saveModel(JAXBElement model, String packageName)

Description

save Model

License

Open Source License

Parameter

Parameter Description
model a parameter
packageName a parameter

Declaration

public static String saveModel(JAXBElement model, String packageName) 

Method Source Code

//package com.java2s;

import java.io.ByteArrayOutputStream;

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

public class Main {
    /**//from  ww w  .  j  av a  2  s  .c o m
     * 
     * @param model
     * @param packageName
     * @return
     */
    public static String saveModel(JAXBElement model, String packageName) {
        JAXBContext jc;
        try {
            jc = JAXBContext.newInstance(packageName);
            Marshaller m = jc.createMarshaller();
            ByteArrayOutputStream o = new ByteArrayOutputStream();
            m.marshal(model, o);

            return new String(o.toByteArray());
        } catch (Exception e) {
            e.printStackTrace();
        }
        return "";
    }
}

Related

  1. deserializeFromXmlFile(T defaultObject, String fileName)
  2. deserializeXmlToJava(String valueType, Serializable value)
  3. save(Class confClass, Object confObj, File xmlFile)
  4. save(File file, T obj, Class... clazz)
  5. saveDataToFile(File file, T data)
  6. saveObject(Path path, T object)
  7. saveObject(T object, Class typeClass, URL path)
  8. saveToFile(String fileName, T obj)
  9. saveXML(Object object, String fileNamePath, Boolean append)