当前位置: 首页>>代码示例>>Java>>正文


Java TreeMarshaller类代码示例

本文整理汇总了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));
}
 
开发者ID:x-stream,项目名称:xstream,代码行数:20,代码来源:ToAttributedValueConverterTest.java

示例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));
}
 
开发者ID:x-stream,项目名称:xstream,代码行数:23,代码来源:ToAttributedValueConverterTest.java

示例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);
}
 
开发者ID:x-stream,项目名称:xstream,代码行数:21,代码来源:ToAttributedValueConverterTest.java

示例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));
}
 
开发者ID:x-stream,项目名称:xstream,代码行数:20,代码来源:ToAttributedValueConverterTest.java

示例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));
}
 
开发者ID:x-stream,项目名称:xstream,代码行数:23,代码来源:ToAttributedValueConverterTest.java

示例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);
    }
}
 
开发者ID:x-stream,项目名称:xstream,代码行数:18,代码来源:ToAttributedValueConverterTest.java

示例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]);
}
 
开发者ID:x-stream,项目名称:xstream,代码行数:32,代码来源:ToAttributedValueConverterTest.java

示例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);
}
 
开发者ID:phoglenix,项目名称:bt-builder,代码行数:6,代码来源:NameAsIdReferenceMarshallingStrategy.java

示例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);
}
 
开发者ID:micromata,项目名称:projectforge-webapp,代码行数:6,代码来源:XStreamMarshallingStrategy.java


注:本文中的com.thoughtworks.xstream.core.TreeMarshaller类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。