From 9cbe8891fe698e4aeec1aca4b13d8ec868ccdf0a Mon Sep 17 00:00:00 2001 From: joehni Date: Fri, 27 Dec 2024 23:39:35 +0100 Subject: [PATCH] Add unit test omitting a legacy outer-class element. --- .../acceptance/OmitFieldsTest.java | 33 ++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/xstream/src/test/com/thoughtworks/acceptance/OmitFieldsTest.java b/xstream/src/test/com/thoughtworks/acceptance/OmitFieldsTest.java index 84d461c0a..f02b928ef 100644 --- a/xstream/src/test/com/thoughtworks/acceptance/OmitFieldsTest.java +++ b/xstream/src/test/com/thoughtworks/acceptance/OmitFieldsTest.java @@ -1,6 +1,6 @@ /* * Copyright (C) 2005 Joe Walnes. - * Copyright (C) 2006, 2007, 2010, 2012, 2013, 2014, 2018, 2020, 2021 XStream Committers. + * Copyright (C) 2006, 2007, 2010, 2012, 2013, 2014, 2018, 2020, 2021, 2024 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -548,4 +548,35 @@ public void testReferencedElementsCanBeIgnored() { final Wrapper out = xstream.fromXML(expectedXml); assertEquals("junit", out.member.name); } + + public void testOmitFormerOuterClass() { + final Thing in = new Thing(); + in.alwaysIgnore = "a"; + in.sometimesIgnore = "b"; + in.neverIgnore = "c"; + + final String expectedXml = "" + + "\n" + + " b\n" + + " c\n" + + ""; + + xstream.alias("thing", Thing.class); + xstream.aliasField("outer-class", Thing.class, "alwaysIgnore"); + + final String actualXml = xstream.toXML(in); + assertEquals(expectedXml, actualXml); + + final String legacyXml = "" + + "\n" + + " \n" + + " some value" + + " \n" + + " b\n" + + " c\n" + + ""; + + final Thing out = xstream.fromXML(legacyXml); + assertEquals(in, out); + } }