Java XML JAXB Marshaller marshal(JAXBContext context, Object object, Writer writer, Map properties)

Here you can find the source of marshal(JAXBContext context, Object object, Writer writer, Map properties)

Description

marshal

License

Apache License

Declaration


public static void marshal(JAXBContext context, Object object, Writer writer, Map<String, Object> properties)
        throws JAXBException 

Method Source Code


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

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

import java.io.StringWriter;
import java.io.Writer;
import java.util.*;

public class Main {

    public static void marshal(JAXBContext context, Object object, Writer writer, Map<String, Object> properties)
            throws JAXBException {
        if (object == null) {
            return;
        }/*from ww w .  j  a  v a 2 s. c  om*/

        if (writer == null) {
            return;
        }

        if (context == null) {
            context = JAXBContext.newInstance(object.getClass());
        }

        Marshaller marshaller = context.createMarshaller();
        if (properties != null) {
            Iterator<Map.Entry<String, Object>> it = properties.entrySet().iterator();
            while (it.hasNext()) {
                Map.Entry<String, Object> entry = it.next();
                marshaller.setProperty(entry.getKey(), entry.getValue());
            }
        }
        marshaller.marshal(object, writer);
    }

    public static String marshal(JAXBContext context, Object object, Map<String, Object> properties)
            throws JAXBException {
        StringWriter writer = new StringWriter();
        marshal(context, object, writer, properties);
        return writer.toString();
    }

    public static String marshal(Object object) throws JAXBException {
        StringWriter writer = new StringWriter();
        marshal(null, object, writer, null);
        return writer.toString();
    }
}

Related

  1. marshal(Class clazz, T obj)
  2. marshal(Class clazz, T object)
  3. marshal(final Object obj, final Class... classes)
  4. marshal(final Object object)
  5. marshal(final Object object)
  6. marshal(JAXBElement e, File f)
  7. marshal(JAXBElement jaxbElement, Class cls)
  8. marshal(JAXBElement value, String contextPath, OutputStream out, ClassLoader classLoader)
  9. marshal(Marshaller m, File out, Object o)