1
1
package com .fasterxml .jackson .databind .deser .jdk ;
2
2
3
- import java .util .Objects ;
3
+ import java .util .* ;
4
4
import java .util .concurrent .atomic .AtomicReference ;
5
5
6
6
import org .junit .jupiter .api .Test ;
@@ -90,6 +90,27 @@ public boolean equals(Object obj) {
90
90
}
91
91
}
92
92
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
+
93
114
@ Test
94
115
public void testRoundTrip () throws Exception {
95
116
_test (new AtomicReference <>("MyName" ), String .class );
@@ -98,11 +119,42 @@ public void testRoundTrip() throws Exception {
98
119
}
99
120
100
121
@ Test
101
- public void testPolymorphic () throws Exception {
122
+ public void testPolymorphicWrapperObject () throws Exception {
123
+ // Note that default typing set to WRAPPER_OBJECT as well
102
124
_test (new AtomicReference <>(new Dog ("Buddy" )), Animal .class );
125
+ }
126
+
127
+ @ Test
128
+ public void testPolymorphicProperty () throws Exception {
103
129
_test (new AtomicReference <>(new Dog2 ("Buttercup" )), Animal2 .class );
104
130
}
105
131
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
+
106
158
private final ObjectMapper STD_RESOLVER_MAPPER = jsonMapperBuilder ()
107
159
// this is what's causing failure in later versions.....
108
160
.setDefaultTyping (
0 commit comments