本文整理汇总了Java中com.thoughtworks.xstream.core.TreeMarshaller类的典型用法代码示例。如果您正苦于以下问题:Java TreeMarshaller类的具体用法?Java TreeMarshaller怎么用?Java TreeMarshaller使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
TreeMarshaller类属于com.thoughtworks.xstream.core包,在下文中一共展示了TreeMarshaller类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testWithValueInConvertedClass
import com.thoughtworks.xstream.core.TreeMarshaller; //导入依赖的package包/类
/**
* Tests conversion with field defined in converted class.
*/
public void testWithValueInConvertedClass() {
converterLookup.registerConverter(new ToAttributedValueConverter(
Software.class, mapper, reflectionProvider, converterLookup, "name"), 0);
final Software name = new Software(null, "XStream");
final StringWriter writer = new StringWriter();
final CompactWriter compactWriter = new CompactWriter(writer);
new TreeMarshaller(compactWriter, converterLookup, mapper).start(name, null);
compactWriter.flush();
assertEquals("<software>XStream</software>", writer.toString());
final HierarchicalStreamReader reader = driver.createReader(new StringReader(
writer.toString()));
assertEquals(
name, new TreeUnmarshaller(null, reader, converterLookup, mapper).start(null));
}
示例2: testWithValueInSuperclass
import com.thoughtworks.xstream.core.TreeMarshaller; //导入依赖的package包/类
/**
* Tests conversion with field defined in superclass.
*/
public void testWithValueInSuperclass() {
converterLookup.registerConverter(new ToAttributedValueConverter(
OpenSourceSoftware.class, mapper, reflectionProvider, converterLookup, "name",
Software.class), 0);
final Software software = new OpenSourceSoftware("Codehaus", "XStream", "BSD");
final StringWriter writer = new StringWriter();
final CompactWriter compactWriter = new CompactWriter(writer);
new TreeMarshaller(compactWriter, converterLookup, mapper).start(software, null);
compactWriter.flush();
assertEquals(
"<open-source vendor=\"Codehaus\" license=\"BSD\">XStream</open-source>",
writer.toString());
final HierarchicalStreamReader reader = driver.createReader(new StringReader(
writer.toString()));
assertEquals(
software, new TreeUnmarshaller(null, reader, converterLookup, mapper).start(null));
}
示例3: testWithNullValueDeserializedAsEmptyString
import com.thoughtworks.xstream.core.TreeMarshaller; //导入依赖的package包/类
/**
* Tests conversion with null in field value.
*/
public void testWithNullValueDeserializedAsEmptyString() {
converterLookup.registerConverter(new ToAttributedValueConverter(
Software.class, mapper, reflectionProvider, converterLookup, "name"), 0);
final Software software = new Software(null, null);
final StringWriter writer = new StringWriter();
final CompactWriter compactWriter = new CompactWriter(writer);
new TreeMarshaller(compactWriter, converterLookup, mapper).start(software, null);
compactWriter.flush();
assertEquals("<software/>", writer.toString());
final HierarchicalStreamReader reader = driver.createReader(new StringReader(
writer.toString()));
assertEquals(
"",
((Software)new TreeUnmarshaller(null, reader, converterLookup, mapper).start(null)).name);
}
示例4: testWithoutValueField
import com.thoughtworks.xstream.core.TreeMarshaller; //导入依赖的package包/类
/**
* Tests conversion with null in field value.
*/
public void testWithoutValueField() {
converterLookup.registerConverter(new ToAttributedValueConverter(
Software.class, mapper, reflectionProvider, converterLookup, null), 0);
final Software software = new Software("Codehaus", "XStream");
final StringWriter writer = new StringWriter();
final CompactWriter compactWriter = new CompactWriter(writer);
new TreeMarshaller(compactWriter, converterLookup, mapper).start(software, null);
compactWriter.flush();
assertEquals("<software vendor=\"Codehaus\" name=\"XStream\"/>", writer.toString());
final HierarchicalStreamReader reader = driver.createReader(new StringReader(
writer.toString()));
assertEquals(
software, new TreeUnmarshaller(null, reader, converterLookup, mapper).start(null));
}
示例5: testWithComplexValueField
import com.thoughtworks.xstream.core.TreeMarshaller; //导入依赖的package包/类
/**
* Tests conversion with complex value field.
*/
public void testWithComplexValueField() {
converterLookup.registerConverter(new ToAttributedValueConverter(
X.class, mapper, reflectionProvider, converterLookup, "innerObj"), 0);
final X x = new X(42);
x.aStr = "xXx";
x.innerObj = new Y();
x.innerObj.yField = "inner";
final StringWriter writer = new StringWriter();
final CompactWriter compactWriter = new CompactWriter(writer);
new TreeMarshaller(compactWriter, converterLookup, mapper).start(x, null);
compactWriter.flush();
assertEquals(
"<x aStr=\"xXx\" anInt=\"42\"><yField>inner</yField></x>", writer.toString());
final HierarchicalStreamReader reader = driver.createReader(new StringReader(
writer.toString()));
assertEquals(x, new TreeUnmarshaller(null, reader, converterLookup, mapper).start(null));
}
示例6: testFailsWhenFieldCannotBeWrittenAsAttribute
import com.thoughtworks.xstream.core.TreeMarshaller; //导入依赖的package包/类
public void testFailsWhenFieldCannotBeWrittenAsAttribute() {
converterLookup.registerConverter(new ToAttributedValueConverter(
X.class, mapper, reflectionProvider, converterLookup, "aStr"), 0);
final X x = new X(42);
x.aStr = "xXx";
x.innerObj = new Y();
x.innerObj.yField = "inner";
final StringWriter writer = new StringWriter();
final CompactWriter compactWriter = new CompactWriter(writer);
try {
new TreeMarshaller(compactWriter, converterLookup, mapper).start(x, null);
fail("Thrown " + ConversionException.class.getName() + " expected");
} catch (final ConversionException e) {
assertTrue(e.getMessage().indexOf("innerObj") >= 0);
}
}
示例7: testWillDistinguishBetweenDifferentTypes
import com.thoughtworks.xstream.core.TreeMarshaller; //导入依赖的package包/类
/**
* Tests conversion distinguishes between different types.
*/
public void testWillDistinguishBetweenDifferentTypes() {
converterLookup.registerConverter(new ToAttributedValueConverter(
Software.class, mapper, reflectionProvider, converterLookup, "name"), 0);
converterLookup.registerConverter(
new ToAttributedValueConverter(
OpenSourceSoftware.class, mapper, reflectionProvider, converterLookup,
"license"), 0);
final Software[] software = new Software[]{
new Software("Microsoft", "Windows"),
new OpenSourceSoftware("Codehaus", "XStream", "BSD")};
final StringWriter writer = new StringWriter();
final PrettyPrintWriter prettyPrintWriter = new PrettyPrintWriter(writer);
new TreeMarshaller(prettyPrintWriter, converterLookup, mapper).start(software, null);
prettyPrintWriter.flush();
assertEquals(""
+ "<software-array>\n"
+ " <software vendor=\"Microsoft\">Windows</software>\n"
+ " <open-source vendor=\"Codehaus\" name=\"XStream\">BSD</open-source>\n"
+ "</software-array>", writer.toString());
final HierarchicalStreamReader reader = driver.createReader(new StringReader(
writer.toString()));
Software[] array = (Software[])new TreeUnmarshaller(
null, reader, converterLookup, mapper).start(null);
assertEquals(software[0], array[0]);
assertEquals(software[1], array[1]);
}
示例8: createMarshallingContext
import com.thoughtworks.xstream.core.TreeMarshaller; //导入依赖的package包/类
@Override
protected TreeMarshaller createMarshallingContext(
HierarchicalStreamWriter writer, ConverterLookup converterLookup, Mapper mapper) {
return new ReferenceByNameIdMarshaller(writer, converterLookup, mapper);
}
示例9: createMarshallingContext
import com.thoughtworks.xstream.core.TreeMarshaller; //导入依赖的package包/类
@Override
protected TreeMarshaller createMarshallingContext(HierarchicalStreamWriter writer, ConverterLookup converterLookup, Mapper mapper)
{
return new HibernateProxyXPathMarshaller(writer, converterLookup, mapper, RELATIVE);
}