Here you can find the source of marshall(Object toMarshall)
Parameter | Description |
---|---|
toMarshall | the object to Marshall |
Parameter | Description |
---|---|
JAXBException | if there is an error marshalling the object |
public static final InputStream marshall(Object toMarshall) throws IOException
//package com.java2s; import java.io.IOException; import java.io.InputStream; import java.io.StringWriter; import javax.xml.bind.JAXBContext; import javax.xml.bind.Marshaller; import com.amazonaws.util.StringInputStream; public class Main { /**//from w w w .j a v a 2s. c o m * Marshalls the object to a String. <br/> * Example: <code> * String marshalled = JaxbUtil.marshall(env); * </code> * * @param toMarshall * the object to Marshall * @return the String representation * @throws JAXBException * if there is an error marshalling the object */ public static final InputStream marshall(Object toMarshall) throws IOException { StringWriter sw = null; try { JAXBContext ctx = JAXBContext.newInstance(toMarshall.getClass().getPackage().getName()); sw = new StringWriter(); Marshaller marshaller = ctx.createMarshaller(); marshaller.setProperty("jaxb.formatted.output", true); marshaller.marshal(toMarshall, sw); } catch (Exception e) { throw new RuntimeException(e); } return new StringInputStream(sw.toString()); } }