Skip to content

Commit 4cef254

Browse files
committed
Fix AtomicReferenceSerializer.isEmpty to prevent class cast exception.
1 parent c674b76 commit 4cef254

File tree

2 files changed

+41
-1
lines changed

2 files changed

+41
-1
lines changed

src/main/java/com/fasterxml/jackson/databind/ser/std/AtomicReferenceSerializer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ public boolean isEmpty(SerializerProvider provider, AtomicReference<?> value)
224224
JsonSerializer<Object> ser = _valueSerializer;
225225
if (ser == null) {
226226
try {
227-
ser = _findCachedSerializer(provider, value.getClass());
227+
ser = _findCachedSerializer(provider, contents.getClass());
228228
} catch (JsonMappingException e) { // nasty but necessary
229229
throw new RuntimeJsonMappingException(e);
230230
}

src/test/java/com/fasterxml/jackson/databind/deser/TestJDKAtomicTypes.java

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,46 @@ public void testAbsentExclusion() throws Exception
137137
mapper.writeValueAsString(new SimpleWrapper(null)));
138138
}
139139

140+
public void testSerPropInclusionAlways() throws Exception
141+
{
142+
JsonInclude.Value incl =
143+
JsonInclude.Value.construct(JsonInclude.Include.NON_ABSENT, JsonInclude.Include.ALWAYS);
144+
ObjectMapper mapper = new ObjectMapper();
145+
mapper.setPropertyInclusion(incl);
146+
assertEquals(aposToQuotes("{'value':true}"),
147+
mapper.writeValueAsString(new SimpleWrapper(Boolean.TRUE)));
148+
}
149+
150+
public void testSerPropInclusionNonNull() throws Exception
151+
{
152+
JsonInclude.Value incl =
153+
JsonInclude.Value.construct(JsonInclude.Include.NON_ABSENT, JsonInclude.Include.NON_NULL);
154+
ObjectMapper mapper = new ObjectMapper();
155+
mapper.setPropertyInclusion(incl);
156+
assertEquals(aposToQuotes("{'value':true}"),
157+
mapper.writeValueAsString(new SimpleWrapper(Boolean.TRUE)));
158+
}
159+
160+
public void testSerPropInclusionNonAbsent() throws Exception
161+
{
162+
JsonInclude.Value incl =
163+
JsonInclude.Value.construct(JsonInclude.Include.NON_ABSENT, JsonInclude.Include.NON_ABSENT);
164+
ObjectMapper mapper = new ObjectMapper();
165+
mapper.setPropertyInclusion(incl);
166+
assertEquals(aposToQuotes("{'value':true}"),
167+
mapper.writeValueAsString(new SimpleWrapper(Boolean.TRUE)));
168+
}
169+
170+
public void testSerPropInclusionNonEmpty() throws Exception
171+
{
172+
JsonInclude.Value incl =
173+
JsonInclude.Value.construct(JsonInclude.Include.NON_ABSENT, JsonInclude.Include.NON_EMPTY);
174+
ObjectMapper mapper = new ObjectMapper();
175+
mapper.setPropertyInclusion(incl);
176+
assertEquals(aposToQuotes("{'value':true}"),
177+
mapper.writeValueAsString(new SimpleWrapper(Boolean.TRUE)));
178+
}
179+
140180
// [databind#340]
141181
public void testPolymorphicAtomicReference() throws Exception
142182
{

0 commit comments

Comments
 (0)