本文整理了Java中com.thoughtworks.xstream.XStream.marshal()
方法的一些代码示例,展示了XStream.marshal()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。XStream.marshal()
方法的具体详情如下:
包路径:com.thoughtworks.xstream.XStream
类名称:XStream
方法名:marshal
[英]Serialize and object to a hierarchical data structure (such as XML).
[中]序列化和对象到分层数据结构(如XML)。
代码示例来源:origin: com.thoughtworks.xstream/xstream
/**
* Serialize and object to a hierarchical data structure (such as XML).
*
* @throws XStreamException if the object cannot be serialized
*/
public void marshal(Object obj, HierarchicalStreamWriter writer) {
marshal(obj, writer, null);
}
代码示例来源:origin: com.thoughtworks.xstream/xstream
public void writeToStream(final Object object) {
marshal(object, statefulWriter, dataHolder);
}
代码示例来源:origin: jenkinsci/jenkins
/**
* Marshals the given object with the given XStream into {@link XStreamDOM} and return it.
*/
public static XStreamDOM from(XStream xs, Object obj) {
WriterImpl w = newWriter();
xs.marshal(obj, w);
return w.getOutput();
}
代码示例来源:origin: stackoverflow.com
String strXML = "";
XStream xs = new XStream();
StringWriter sw = new StringWriter();
xs.marshal(this, new CompactWriter(sw));
strXML = sw.toString();
代码示例来源:origin: spring-projects/spring-framework
/**
* Marshals the given graph to the given XStream HierarchicalStreamWriter.
* Converts exceptions using {@link #convertXStreamException}.
*/
private void doMarshal(Object graph, HierarchicalStreamWriter streamWriter, @Nullable DataHolder dataHolder) {
try {
getXStream().marshal(graph, streamWriter, dataHolder);
}
catch (Exception ex) {
throw convertXStreamException(ex, true);
}
finally {
try {
streamWriter.flush();
}
catch (Exception ex) {
logger.debug("Could not flush HierarchicalStreamWriter", ex);
}
}
}
代码示例来源:origin: javamelody/javamelody
static void writeToXml(Serializable serializable, BufferedOutputStream bufferedOutput)
throws IOException {
final XStream xstream = createXStream(false);
// on wrappe avec un CompactWriter pour gagner 25% en taille de flux (retours chariots)
// et donc un peu en performances
final CompactWriter writer = new CompactWriter(
new OutputStreamWriter(bufferedOutput, XML_CHARSET_NAME));
try {
xstream.marshal(serializable, writer);
} finally {
writer.close();
}
}
代码示例来源:origin: com.thoughtworks.xstream/xstream
/**
* Serialize an object to the given OutputStream as pretty-printed XML. The OutputStream
* will be flushed afterwards and in case of an exception.
*
* @throws XStreamException if the object cannot be serialized
*/
public void toXML(Object obj, OutputStream out) {
HierarchicalStreamWriter writer = hierarchicalStreamDriver.createWriter(out);
try {
marshal(obj, writer);
} finally {
writer.flush();
}
}
代码示例来源:origin: com.thoughtworks.xstream/xstream
/**
* Serialize an object to the given Writer as pretty-printed XML. The Writer will be flushed
* afterwards and in case of an exception.
*
* @throws XStreamException if the object cannot be serialized
*/
public void toXML(Object obj, Writer out) {
HierarchicalStreamWriter writer = hierarchicalStreamDriver.createWriter(out);
try {
marshal(obj, writer);
} finally {
writer.flush();
}
}
代码示例来源:origin: com.thoughtworks.xstream/xstream
this.startDocument(true);
for (Iterator i = source.iterator(); i.hasNext();) {
xstream.marshal(i.next(), this);
代码示例来源:origin: hcoles/pitest
public static String toXml(final Object o) {
final Writer writer = new StringWriter();
XSTREAM_INSTANCE.marshal(o, new CompactWriter(writer));
return writer.toString();
}
代码示例来源:origin: x-stream/xstream
/**
* Serialize and object to a hierarchical data structure (such as XML).
*
* @throws XStreamException if the object cannot be serialized
*/
public void marshal(final Object obj, final HierarchicalStreamWriter writer) {
marshal(obj, writer, null);
}
代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.xstream
/**
* Serialize and object to a hierarchical data structure (such as XML).
*
* @throws XStreamException if the object cannot be serialized
*/
public void marshal(Object obj, HierarchicalStreamWriter writer) {
marshal(obj, writer, null);
}
代码示例来源:origin: com.haulmont.thirdparty/xstream
/**
* Serialize and object to a hierarchical data structure (such as XML).
*
* @throws XStreamException if the object cannot be serialized
*/
public void marshal(Object obj, HierarchicalStreamWriter writer) {
marshal(obj, writer, null);
}
代码示例来源:origin: com.dell.cpsd.component/component-common-core
@Override
public <T> String to(T obj)
{
Writer writer = new StringWriter();
PrettyPrintWriter prettyPrinter = new PrettyPrintWriter(writer);
xstream.marshal(obj, prettyPrinter);
String xml = writer.toString();
if (LOGGER.isDebugEnabled())
LOGGER.debug("XML Output: " + xml);
return xml;
}
代码示例来源:origin: hneemann/Digital
@Override
public void attributeChanged() {
XStream xStream = Circuit.getxStream();
try (Writer out = new OutputStreamWriter(new FileOutputStream(filename), StandardCharsets.UTF_8)) {
out.write("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n");
xStream.marshal(attributes, new PrettyPrintWriter(out));
} catch (Exception e) {
e.printStackTrace();
}
}
代码示例来源:origin: org.cogchar/org.cogchar.lib.convoid
public static Document writeToDom4JDoc(Object obj) {
// dom4JDriver produces a Dom4JXmlWriter, which cannot write mixedContent.
// dom4jDriver.setOutputFormat(dom4jOutputFormat);
XStream xstream = new XStream();
Document targetDoc = DocumentHelper.createDocument();
//BehaviorDataLoader.initBehaviorXStream(xstream);
Dom4JWriter d4jWriter = new Dom4JWriter(targetDoc);
xstream.marshal(obj, d4jWriter);
return targetDoc;
}
public static OutputFormat getPrettyDom4jOutputFormat() {
代码示例来源:origin: org.jenkins-ci.main/jenkins-core
/**
* Marshals the given object with the given XStream into {@link XStreamDOM} and return it.
*/
public static XStreamDOM from(XStream xs, Object obj) {
WriterImpl w = newWriter();
xs.marshal(obj, w);
return w.getOutput();
}
代码示例来源:origin: org.geoserver.extension/gs-wps-core
@Override
public void encode(Object object, ContentHandler handler) throws Exception {
// prepare xml encoding
XStream xstream = buildXStream();
// bind with the content handler
SaxWriter writer = new SaxWriter();
writer.setContentHandler(handler);
// write out xml
xstream.marshal(object, writer);
}
代码示例来源:origin: org.apache.camel/camel-xstream
public void marshal(Exchange exchange, Object body, OutputStream stream) throws Exception {
HierarchicalStreamWriter writer = createHierarchicalStreamWriter(exchange, body, stream);
try {
getXStream(exchange.getContext()).marshal(body, writer);
} finally {
writer.close();
}
}
代码示例来源:origin: x-stream/xstream
@SuppressWarnings("resource")
private void assertBinarySerialization(final Object root) {
// serialize as binary
final ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
xstream.marshal(root, new BinaryStreamWriter(outputStream));
// deserialize the binary and check it equals the original object.
final ByteArrayInputStream inputStream = new ByteArrayInputStream(outputStream.toByteArray());
final Object binaryResult = xstream.unmarshal(new BinaryStreamReader(inputStream));
assertObjectsEqual(root, binaryResult);
}
内容来源于网络,如有侵权,请联系作者删除!