Fix support of implicit collections when using Xstream2 (#5757)

This commit is contained in:
Vincent Latombe authored and GitHub committed 2021-10-10 10:08:16 +01:00
1 parent 7ae5d0e022
commit c7e259ecde
2 files changed
+21 -1

No files matched your search

@@ -32,8 +32,10 @@ import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.converters.ConversionException;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.hamcrest.Matchers;
import org.junit.Test;
/**
@@ -100,6 +102,23 @@ public class RobustReflectionConverterTest {
assertEquals(Billy.class, s.lover.getClass());
}
@Test
public void implicitCollection() {
XStream2 xs = new XStream2();
xs.alias("hold", Hold.class);
xs.addImplicitCollection(Hold.class,"items", "item", String.class);
Hold h = (Hold) xs.fromXML("<hold><item>a</item><item>b</item></hold>");
assertThat(h.items, Matchers.containsInAnyOrder("a", "b"));
assertEquals("<hold>\n" +
" <item>a</item>\n" +
" <item>b</item>\n" +
"</hold>", xs.toXML(h));
}
public static class Hold {
List<String> items;
}
@Retention(RetentionPolicy.RUNTIME) @interface Owner {String value();}
public static class Projekt {
Bild[] bildz;