Java XML JAXB Context toString(JAXBContext context, Object object)

Here you can find the source of toString(JAXBContext context, Object object)

Description

to String

License

Open Source License

Declaration

public static String toString(JAXBContext context, Object object) 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.JAXBException;
import javax.xml.bind.Marshaller;

public class Main {
    public static String toString(JAXBContext context, Object object) throws JAXBException {
        final Marshaller marshaller = context.createMarshaller();
        marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
        final StringWriter sw = new StringWriter();
        marshaller.marshal(object, sw);//from   w w w . ja v  a  2  s .c  o  m
        return sw.toString();
    }
}

Related

  1. getJAXBContextForWebService(Class webService)
  2. getRequestContext()
  3. getRightsContext()
  4. isElement(String contextPath, Object object)
  5. parseXMLFile(String fileName, String contextPath)
  6. toXML(JAXBContext context, T obj)