Skip to content

Commit 1d82c60

Browse files
committed
add a failing test for #1391
1 parent c1478ac commit 1d82c60

1 file changed

Lines changed: 38 additions & 0 deletions

File tree

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package com.fasterxml.jackson.failing;
2+
3+
import java.util.*;
4+
5+
import com.fasterxml.jackson.annotation.JsonTypeInfo;
6+
import com.fasterxml.jackson.databind.*;
7+
8+
// [databind#1391]
9+
public class DefaultTypingOverride1391Test extends BaseMapTest
10+
{
11+
final static ObjectMapper WITH_OBJECT_AND_NON_CONCRETE = new ObjectMapper().enableDefaultTypingAsProperty(
12+
ObjectMapper.DefaultTyping.OBJECT_AND_NON_CONCRETE, "$type");
13+
14+
final static ObjectMapper PLAIN_OBJECT_MAPPER = new ObjectMapper();
15+
16+
static class MyClass {
17+
18+
private final SortedSet<String> treeSetStrings = new TreeSet<>();
19+
20+
@JsonTypeInfo(use = JsonTypeInfo.Id.NONE)
21+
public SortedSet<String> getTreeSetStrings() {
22+
return this.treeSetStrings;
23+
}
24+
}
25+
26+
public void testCollectionTyping() throws Exception {
27+
28+
final MyClass toSerialize = new MyClass();
29+
30+
final String fromPlainObjectMapper = PLAIN_OBJECT_MAPPER.writeValueAsString(toSerialize);
31+
System.out.println("\nfrom plain ObjectMapper:\n" + fromPlainObjectMapper);
32+
33+
final String fromObjectMapperWithDefaultTyping = WITH_OBJECT_AND_NON_CONCRETE.writeValueAsString(toSerialize);
34+
System.out.println("\nfrom ObjectMapper with default typing:\n" + fromObjectMapperWithDefaultTyping);
35+
36+
assertEquals(fromPlainObjectMapper, fromObjectMapperWithDefaultTyping);
37+
}
38+
}

0 commit comments

Comments
 (0)