Skip to content

Commit b88419b

Browse files
committed
Update release notes wrt #3227
1 parent 55a62f6 commit b88419b

File tree

4 files changed

+49
-20
lines changed

4 files changed

+49
-20
lines changed

release-notes/CREDITS-2.x

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1025,6 +1025,8 @@ João Guerra (joca-bt@github)
10251025
* Reported #2770: JsonParser from MismatchedInputException cannot getText() for
10261026
floating-point value
10271027
(2.11.1)
1028+
* Reported #3227: Content `null` handling not working for root values
1029+
(2.13.0)
10281030

10291031
Ryan Bohn (bohnman@github)
10301032
* Reported #2475: `StringCollectionSerializer` calls `JsonGenerator.setCurrentValue(value)`,
@@ -1382,3 +1384,7 @@ Tanvesh Takawale (TanveshT@github)
13821384
* Contributed implementation for #3238: Add PropertyNamingStrategies.UpperSnakeCaseStrategy
13831385
(and UPPER_SNAKE_CASE constant)
13841386
(2.13.0)
1387+
1388+
Hyeonho Kim (proost@github)
1389+
* Contributed fix for #3227: Content `null` handling not working for root values
1390+
(2.13.0)

release-notes/VERSION-2.x

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ Project: jackson-databind
6060
(suggested by Nick B)
6161
#3217: `XMLGregorianCalendar` doesn't work with default typing
6262
(reported by Xinzhe Y)
63+
#3227: Content `null` handling not working for root values
64+
(reported by João G)
65+
(fix contributed by proost@github)
6366
#3238: Add PropertyNamingStrategies.UpperSnakeCaseStrategy (and UPPER_SNAKE_CASE constant)
6467
(requested by Kenneth J)
6568
(contributed by Tanvesh)

src/main/java/com/fasterxml/jackson/databind/deser/std/StdDeserializer.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1885,9 +1885,10 @@ protected Nulls findContentNullStyle(DeserializationContext ctxt, BeanProperty p
18851885
if (prop != null) {
18861886
return prop.getMetadata().getContentNulls();
18871887
}
1888-
1889-
DeserializationConfig config = ctxt.getConfig();
1890-
return config.getDefaultSetterInfo().getContentNulls();
1888+
// 24-Aug-2021, tatu: As per [databind#3227] root values also need
1889+
// to be checked for content nulls
1890+
// NOTE: will this work wrt type-specific overrides? Probably not...
1891+
return ctxt.getConfig().getDefaultSetterInfo().getContentNulls();
18911892
}
18921893

18931894
// @since 2.9

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

Lines changed: 36 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,16 @@ enum EnumMapTestEnum {
8181
A, B, C;
8282
}
8383

84-
private final ObjectMapper MAPPER = objectMapper();
84+
private final ObjectMapper MAPPER = newJsonMapper();
8585

86+
private final ObjectMapper CONTENT_NULL_FAIL_MAPPER = JsonMapper.builder()
87+
.defaultSetterInfo(JsonSetter.Value.construct(Nulls.AS_EMPTY, Nulls.FAIL))
88+
.build();
89+
8690
/*
87-
/**********************************************************
91+
/**********************************************************************
8892
/* Test methods
89-
/**********************************************************
93+
/**********************************************************************
9094
*/
9195

9296
public void testNull() throws Exception
@@ -205,58 +209,73 @@ public void testPolymorphicDataNull() throws Exception
205209
assertNull("Proxy should be null!", typeBNullData.proxy);
206210
}
207211

208-
// Test for databind #3227
209-
public void testNullsFailIfContentValueIsNull() throws Exception {
210-
ObjectMapper objectMapper = JsonMapper.builder()
211-
.defaultSetterInfo(JsonSetter.Value.construct(Nulls.FAIL, Nulls.FAIL))
212-
.build();
213-
212+
// Test for [databind#3227]
213+
public void testContentsNullFailForMaps() throws Exception
214+
{
214215
try {
215-
objectMapper.readValue("{ \"field\": null, \"property\": '1' }", Map.class);
216+
CONTENT_NULL_FAIL_MAPPER.readValue("{ \"field\": null, \"property\": 1 }", Map.class);
216217
fail("InvalidNullException expected");
217218
} catch (InvalidNullException e) {
219+
verifyException(e, "Invalid `null` value encountered");
218220
}
219221

220222
try {
221-
objectMapper.readValue("{ \"A\": 1, \"B\": null }", new TypeReference<EnumMap<EnumMapTestEnum, Integer>>() {});
223+
CONTENT_NULL_FAIL_MAPPER.readValue("{ \"A\": 1, \"B\": null }", new TypeReference<EnumMap<EnumMapTestEnum, Integer>>() {});
222224
fail("InvalidNullException expected");
223225
} catch (InvalidNullException e) {
226+
verifyException(e, "Invalid `null` value encountered");
224227
}
228+
}
225229

230+
// Test for [databind#3227]
231+
public void testContentsNullFailForCollections() throws Exception
232+
{
226233
try {
227-
objectMapper.readValue("[null, {\"field\": 1}]", new TypeReference<List<Object>>() {});
234+
CONTENT_NULL_FAIL_MAPPER.readValue("[null, {\"field\": 1}]",
235+
new TypeReference<List<Object>>() {});
228236
fail("InvalidNullException expected");
229237
} catch (InvalidNullException e) {
238+
verifyException(e, "Invalid `null` value encountered");
230239
}
231240

232241
try {
233-
objectMapper.readValue("[{\"field\": 1}, null]", new TypeReference<Set<Object>>() {});
242+
CONTENT_NULL_FAIL_MAPPER.readValue("[{\"field\": 1}, null]",
243+
new TypeReference<Set<Object>>() {});
234244
fail("InvalidNullException expected");
235245
} catch (InvalidNullException e) {
246+
verifyException(e, "Invalid `null` value encountered");
236247
}
237248

238249
try {
239-
objectMapper.readValue("[null, {\"field\": 1}]", Object[].class);
250+
CONTENT_NULL_FAIL_MAPPER.readValue("[\"foo\", null]", new TypeReference<List<String>>() {});
240251
fail("InvalidNullException expected");
241252
} catch (InvalidNullException e) {
253+
verifyException(e, "Invalid `null` value encountered");
242254
}
243255

244256
try {
245-
objectMapper.readValue("[\"foo\", null]", new TypeReference<List<String>>() {});
257+
CONTENT_NULL_FAIL_MAPPER.readValue("[\"foo\", null]", new TypeReference<Set<String>>() {});
246258
fail("InvalidNullException expected");
247259
} catch (InvalidNullException e) {
260+
verifyException(e, "Invalid `null` value encountered");
248261
}
262+
}
249263

264+
// Test for [databind#3227]
265+
public void testContentsNullFailForArrays() throws Exception
266+
{
250267
try {
251-
objectMapper.readValue("[\"foo\", null]", new TypeReference<Set<String>>() {});
268+
CONTENT_NULL_FAIL_MAPPER.readValue("[null, {\"field\": 1}]", Object[].class);
252269
fail("InvalidNullException expected");
253270
} catch (InvalidNullException e) {
271+
verifyException(e, "Invalid `null` value encountered");
254272
}
255273

256274
try {
257-
objectMapper.readValue("[null, \"foo\"]", String[].class);
275+
CONTENT_NULL_FAIL_MAPPER.readValue("[null, \"foo\"]", String[].class);
258276
fail("InvalidNullException expected");
259277
} catch (InvalidNullException e) {
278+
verifyException(e, "Invalid `null` value encountered");
260279
}
261280
}
262281
}

0 commit comments

Comments
 (0)