Skip to content

Commit 940034d

Browse files
committed
Test : Add more
1 parent 1b3f3d9 commit 940034d

File tree

1 file changed

+54
-2
lines changed

1 file changed

+54
-2
lines changed

src/test/java/com/fasterxml/jackson/databind/deser/jdk/AtomicReferenceWithStdTypeResolverBuilder4838Test.java

Lines changed: 54 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package com.fasterxml.jackson.databind.deser.jdk;
22

3-
import java.util.Objects;
3+
import java.util.*;
44
import java.util.concurrent.atomic.AtomicReference;
55

66
import org.junit.jupiter.api.Test;
@@ -90,6 +90,27 @@ public boolean equals(Object obj) {
9090
}
9191
}
9292

93+
@JsonTypeInfo(use = JsonTypeInfo.Id.CLASS, include = JsonTypeInfo.As.WRAPPER_ARRAY)
94+
static abstract class Animal3 {
95+
public String name;
96+
97+
protected Animal3(String name) {
98+
this.name = name;
99+
}
100+
}
101+
102+
static class Dog3 extends Animal3 {
103+
@JsonCreator
104+
public Dog3(@JsonProperty("name") String name) {
105+
super(name);
106+
}
107+
108+
@Override
109+
public boolean equals(Object obj) {
110+
return (obj instanceof Dog3) && name.equals(((Dog3) obj).name);
111+
}
112+
}
113+
93114
@Test
94115
public void testRoundTrip() throws Exception {
95116
_test(new AtomicReference<>("MyName"), String.class);
@@ -98,11 +119,42 @@ public void testRoundTrip() throws Exception {
98119
}
99120

100121
@Test
101-
public void testPolymorphic() throws Exception {
122+
public void testPolymorphicWrapperObject() throws Exception {
123+
// Note that default typing set to WRAPPER_OBJECT as well
102124
_test(new AtomicReference<>(new Dog("Buddy")), Animal.class);
125+
}
126+
127+
@Test
128+
public void testPolymorphicProperty() throws Exception {
103129
_test(new AtomicReference<>(new Dog2("Buttercup")), Animal2.class);
104130
}
105131

132+
@Test
133+
public void testPolymorphicWrapperArray() throws Exception {
134+
_test(new AtomicReference<>(new Dog3("Buddy")), Animal3.class);
135+
}
136+
137+
@Test
138+
public void testAtomicReferenceWithMapAndCollection() throws Exception {
139+
// Test AtomicReference with Map
140+
Map<String, Integer> sampleMap = new HashMap<>();
141+
sampleMap.put("key1", 1);
142+
sampleMap.put("key2", 2);
143+
_test(new AtomicReference<>(sampleMap), Map.class);
144+
145+
// Test AtomicReference with List
146+
List<String> sampleList = Arrays.asList("value1", "value2", "value3");
147+
_test(new AtomicReference<>(sampleList), List.class);
148+
149+
// Test AtomicReference with Set
150+
Set<Integer> sampleSet = new HashSet<>(Arrays.asList(1, 2, 3));
151+
_test(new AtomicReference<>(sampleSet), Set.class);
152+
153+
// Test AtomicReference with Queue
154+
Queue<String> sampleQueue = new LinkedList<>(Arrays.asList("q1", "q2", "q3"));
155+
_test(new AtomicReference<>(sampleQueue), Queue.class);
156+
}
157+
106158
private final ObjectMapper STD_RESOLVER_MAPPER = jsonMapperBuilder()
107159
// this is what's causing failure in later versions.....
108160
.setDefaultTyping(

0 commit comments

Comments
 (0)