blob: bbb9bcfd92de5a3f6753563f7b3aed0b320c2309 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
package com.fasterxml.jackson.databind.struct;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonSubTypes;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
import com.fasterxml.jackson.databind.BaseMapTest;
import com.fasterxml.jackson.databind.ObjectMapper;
public class TestPOJOAsArrayPolymorphic extends BaseMapTest
{
// [databind#2077]
@JsonTypeInfo(
use = JsonTypeInfo.Id.NAME,
include = JsonTypeInfo.As.WRAPPER_ARRAY) // Both WRAPPER_OBJECT and WRAPPER_ARRAY cause the same problem
@JsonSubTypes({
@JsonSubTypes.Type(value = DirectLayout.class, name = "Direct"),
})
public interface Layout {
}
@JsonFormat(shape=JsonFormat.Shape.ARRAY)
public static class DirectLayout implements Layout {
}
private final ObjectMapper MAPPER = sharedMapper();
// [databind#2077]
public void testPolymorphicAsArray() throws Exception
{
// 20-Sep-2019, taut: this fails to add shape information, due to class annotations
// not being checked due to missing `property` for `createContextual()`
String json = MAPPER.writeValueAsString(new DirectLayout());
Layout instance = MAPPER.readValue(json, Layout.class);
assertNotNull(instance);
}
}
|