public void testAllowsNamedFields() { ObjectWithNamedFields obj = new ObjectWithNamedFields(); obj.name = "Joe"; obj.number = 99; obj.someSoftware = new Software("tw", "xs"); obj.polymorphic = new Hardware("small", "ipod"); obj.nothing = null; xstream.alias("with-named-fields", ObjectWithNamedFields.class); xstream.alias("software", Software.class); String expectedXml = "" + "<with-named-fields serialization=\"custom\">\n" + " <with-named-fields>\n" + " <default>\n" + " <theName>Joe</theName>\n" + " <theNumber>99</theNumber>\n" + " <theSoftware>\n" + " <vendor>tw</vendor>\n" + " <name>xs</name>\n" + " </theSoftware>\n" + " <thePolymorphic class=\"com.thoughtworks.acceptance.objects.Hardware\">\n" + " <arch>small</arch>\n" + " <name>ipod</name>\n" + " </thePolymorphic>\n" + " </default>\n" + " </with-named-fields>\n" + "</with-named-fields>"; assertBothWays(obj, expectedXml); }
public void testMaintainsBackwardsCompatabilityWithXStream1_1_0FieldFormat() { ObjectWithNamedFields outer = new ObjectWithNamedFields(); outer.name = "Joe"; outer.someSoftware = new Software("tw", "xs"); outer.nothing = null; ObjectWithNamedFields inner = new ObjectWithNamedFields(); inner.name = "Thing"; outer.polymorphic = inner; xstream.alias("with-named-fields", ObjectWithNamedFields.class); xstream.alias("software", Software.class); String oldFormatOfXml = "" + "<with-named-fields serialization=\"custom\">\n" + " <with-named-fields>\n" + " <fields>\n" + " <field name=\"theName\" class=\"string\">Joe</field>\n" + " <field name=\"theNumber\" class=\"int\">0</field>\n" + " <field name=\"theSoftware\" class=\"software\">\n" + " <vendor>tw</vendor>\n" + " <name>xs</name>\n" + " </field>\n" + " <field name=\"thePolymorphic\" class=\"with-named-fields\" serialization=\"custom\">\n" + " <with-named-fields>\n" + " <fields>\n" + " <field name=\"theName\" class=\"string\">Thing</field>\n" + " <field name=\"theNumber\" class=\"int\">0</field>\n" + " </fields>\n" + " </with-named-fields>\n" + " </field>\n" + " </fields>\n" + " </with-named-fields>\n" + "</with-named-fields>"; assertEquals(outer, xstream.fromXML(oldFormatOfXml)); }
public void testCustomStreamWithNestedCustomStream() { ObjectWithNamedFields outer = new ObjectWithNamedFields(); outer.name = "Joe"; outer.someSoftware = new Software("tw", "xs"); outer.nothing = null; ObjectWithNamedFields inner = new ObjectWithNamedFields(); inner.name = "Thing"; outer.polymorphic = inner; xstream.alias("with-named-fields", ObjectWithNamedFields.class); xstream.alias("software", Software.class); String expectedXml = "" + "<with-named-fields serialization=\"custom\">\n" + " <with-named-fields>\n" + " <default>\n" + " <theName>Joe</theName>\n" + " <theNumber>0</theNumber>\n" + " <theSoftware>\n" + " <vendor>tw</vendor>\n" + " <name>xs</name>\n" + " </theSoftware>\n" + " <thePolymorphic class=\"with-named-fields\" serialization=\"custom\">\n" + " <with-named-fields>\n" + " <default>\n" + " <theName>Thing</theName>\n" + " <theNumber>0</theNumber>\n" + " </default>\n" + " </with-named-fields>\n" + " </thePolymorphic>\n" + " </default>\n" + " </with-named-fields>\n" + "</with-named-fields>"; assertBothWays(outer, expectedXml); }