Java Utililty Methods XML JAXB Marshaller

List of utility methods to do XML JAXB Marshaller

Description

The list of methods to do XML JAXB Marshaller are organized into topic(s).

Method

Stringmarshal(Object obj)
marshal
return marshal(obj, obj.getClass());
org.w3c.dom.Elementmarshal(Object obj)
marshal
try {
    Document doc = null;
    JAXBContext jc = getContext(obj.getClass());
    Marshaller marshaller = jc.createMarshaller();
    doc = dbf.newDocumentBuilder().newDocument();
    marshaller.marshal(obj, doc);
    return doc.getDocumentElement();
} catch (ParserConfigurationException ex) {
...
Stringmarshal(Object obj, Class clazz)
marshal
String result = null;
try {
    JAXBContext context = contextMap.get(clazz.getPackage().getName());
    if (context == null) {
        context = JAXBContext.newInstance(clazz.getPackage().getName());
        contextMap.put(clazz.getPackage().getName(), context);
    Marshaller m = context.createMarshaller();
...
voidmarshal(Object obj, OutputStream out)
marshal
try {
    JAXBContext context = JAXBContext.newInstance(obj.getClass());
    Marshaller marshaller = context.createMarshaller();
    marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
    marshaller.marshal(obj, out);
} catch (JAXBException e) {
    throw new RuntimeException(e);
voidmarshal(Object obj, OutputStream out, Class... boundClasses)
marshal
try {
    Marshaller m = JAXBContext.newInstance(boundClasses).createMarshaller();
    m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
    m.marshal(obj, out);
} catch (Exception ex) {
voidmarshal(Object obj, OutputStream stream)
marshal
JAXB.marshal(obj, stream);
Stringmarshal(Object object)
marshal
StringWriter string = new StringWriter();
JAXBContext jaxbContext = JAXBContext.newInstance(object.getClass());
Marshaller marshaller = jaxbContext.createMarshaller();
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.FALSE);
marshaller.setProperty(Marshaller.JAXB_ENCODING, "UTF-8"); 
marshaller.marshal(object, string);
return string.toString();
Stringmarshal(Object object)
marshal
try {
    StringWriter writer = new StringWriter();
    JAXBContext jaxbContext = JAXBContext.newInstance(object.getClass());
    Marshaller marshaller = jaxbContext.createMarshaller();
    marshaller.marshal(object, writer);
    return writer.toString();
} catch (JAXBException e) {
    throw new RuntimeException("Error marshalling object", e);
...
Stringmarshal(Object object)
marshal
StringWriter writer = new StringWriter();
JAXB.marshal(object, writer);
return writer.toString();
voidmarshal(Object object, File file, JAXBContext ctx)
marshal
Marshaller m = ctx.createMarshaller();
m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
m.marshal(object, file);