Java XML JAXB Marshaller marshalV2(Class clazz, T obj, String uri, String nodeName)

Here you can find the source of marshalV2(Class clazz, T obj, String uri, String nodeName)

Description

marshal V

License

Open Source License

Declaration

public static <T> String marshalV2(Class<T> clazz, T obj, String uri, String nodeName) throws JAXBException 

Method Source Code

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

import java.io.StringWriter;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBElement;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;
import javax.xml.namespace.QName;

public class Main {
    public static <T> String marshalV2(Class<T> clazz, T obj, String uri, String nodeName) throws JAXBException {
        StringWriter out = new StringWriter();
        JAXBContext context = JAXBContext.newInstance(clazz);
        Marshaller m = context.createMarshaller();
        m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
        m.marshal(new JAXBElement<T>(new QName(uri, nodeName), clazz, obj), out);
        return out.toString();
    }//from  ww  w. j  a v a2 s  .c o m

    public static <T> String marshal(Class<T> clazz, T obj) throws JAXBException {
        StringWriter out = new StringWriter();
        JAXBContext context = JAXBContext.newInstance(clazz);
        Marshaller m = context.createMarshaller();
        m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
        m.marshal(obj, out);
        return out.toString();
    }
}

Related

  1. marshalObject(Object obj, File file)
  2. marshalObjectToXml(Object object, String xmlFilePath)
  3. marshalPackage(OutputStream printStream, final Package p)
  4. marshalToString(Object obj)
  5. marshalToString(Object obj)
  6. removeStandalone(final Marshaller marshaller)
  7. setEncoding(@Nonnull final Marshaller aMarshaller, @Nullable final Charset aEncoding)
  8. xmlMarshal(Object obj, Class clazz)