Skip to content

Commit 176ce1a

Browse files
committed
Add passing test for #767 (fixed by earlier #762 fix)
1 parent d733370 commit 176ce1a

File tree

3 files changed

+54
-1
lines changed

3 files changed

+54
-1
lines changed

release-notes/CREDITS

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,12 @@ Severin Kistler (@kistlers)
6464
Simon Cockx (@SimonCockx)
6565
* Reported #762: Unwrapping lists does not work inside `@JsonUnwrapped`
6666
(3.2.0)
67-
67+
68+
Veit-Hendrik Schlenker (@vhschlenker)
69+
* Reported #767: Unwrapped lists cannot be deserialized when using
70+
`JsonTypeInfo.As.EXISTING_PROPERTY`
71+
(3.2.0)
72+
6873
Charles Moulliard (@cmoulliard)
6974
* Reported #795: `HttpHeader` object (= <httpHeaders>) is not wrapped by the XML `<property>` tag
7075
(3.2.0)

release-notes/VERSION

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ Version: 3.x (for earlier see VERSION-2.x)
4747
#762: Unwrapping lists does not work inside `@JsonUnwrapped`
4848
(reported by Simon C)
4949
(fix by @cowtowncoder, w/ Claude code)
50+
#767: Unwrapped lists cannot be deserialized when using
51+
`JsonTypeInfo.As.EXISTING_PROPERTY`
52+
(reported by Veit-Hendrik S)
53+
(fix by @cowtowncoder, w/ Claude code)
5054
#795: `HttpHeader` object (= <httpHeaders>) is not wrapped by the XML `<property>` tag
5155
(reported by Charles M)
5256
(fix by Christopher M)

src/test/java/tools/jackson/dataformat/xml/lists/PolymorphicListDeserTest.java

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,30 @@ public MyType490(
169169
}
170170
}
171171

172+
// [dataformat-xml#767]
173+
@JsonTypeInfo(
174+
use = JsonTypeInfo.Id.NAME,
175+
include = JsonTypeInfo.As.EXISTING_PROPERTY,
176+
property = "type")
177+
@JsonSubTypes({
178+
@JsonSubTypes.Type(value = MyType767.class, name = "myType"),
179+
})
180+
interface IMyType767 { }
181+
182+
static class MyType767 implements IMyType767 {
183+
public final String stringValue;
184+
public final String type = "myType";
185+
public final Collection<String> typeNames;
186+
187+
@JsonCreator
188+
public MyType767(
189+
@JsonProperty("stringValue") String stringValue,
190+
@JsonProperty("typeNames") Collection<String> typeNames) {
191+
this.stringValue = stringValue;
192+
this.typeNames = typeNames;
193+
}
194+
}
195+
172196
// [dataformat-xml#567]
173197
@JsonRootName("wrapper")
174198
static class Wrapper567 extends Base567 {
@@ -321,6 +345,26 @@ public void testPolymorphicUnwrappedList490() throws Exception
321345
assertEquals(Arrays.asList("type1", "type2"), typedResult.typeNames);
322346
}
323347

348+
// [dataformat-xml#767]: Like #490, but with EXISTING_PROPERTY
349+
@Test
350+
public void testPolymorphicUnwrappedListExistingProperty767() throws Exception
351+
{
352+
XmlMapper xmlMapper = XmlMapper.builder()
353+
.defaultUseWrapper(false).build();
354+
355+
List<String> typeNames = new ArrayList<>();
356+
typeNames.add("type1");
357+
typeNames.add("type2");
358+
MyType767 input = new MyType767("hello", typeNames);
359+
String doc = xmlMapper.writeValueAsString(input);
360+
IMyType767 result = xmlMapper.readValue(doc, IMyType767.class);
361+
362+
assertNotNull(result);
363+
assertEquals(MyType767.class, result.getClass());
364+
MyType767 typedResult = (MyType767) result;
365+
assertEquals(Arrays.asList("type1", "type2"), typedResult.typeNames);
366+
}
367+
324368
// [dataformat-xml#567]
325369
@Test
326370
public void testPolyList567_3items() throws Exception {

0 commit comments

Comments
 (0)