Skip to content

Commit 96d80a4

Browse files
committed
Update release notes wrt #3481
1 parent 96838dc commit 96d80a4

File tree

4 files changed

+13
-6
lines changed

4 files changed

+13
-6
lines changed

release-notes/VERSION-2.x

+3
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ Project: jackson-databind
3030
(reported by Deniz H)
3131
#3476: Implement `JsonNodeFeature.WRITE_NULL_PROPERTIES` to allow skipping
3232
JSON `null` values on writing
33+
#3481: Filter method only got called once if the field is null when using
34+
`@JsonInclude(value = JsonInclude.Include.CUSTOM, valueFilter = SomeFieldFilter.class)`
35+
(contributed by AmiDavidW@github)
3336
#3497: Deserialization of Throwables with PropertyNamingStrategy does not work
3437

3538
2.13.4 (not yet released)

src/main/java/com/fasterxml/jackson/databind/ser/BeanPropertyWriter.java

+4-2
Original file line numberDiff line numberDiff line change
@@ -689,8 +689,10 @@ public void serializeAsField(Object bean, JsonGenerator gen,
689689
: _accessorMethod.invoke(bean, (Object[]) null);
690690

691691
// Null handling is bit different, check that first
692-
if (value == null ) {
693-
if(_suppressableValue != null && _suppressableValue.equals(value)) {
692+
if (value == null) {
693+
// 20-Jun-2022, tatu: Defer checking of null, see [databind#3481]
694+
if((_suppressableValue != null)
695+
&& prov.includeFilterSuppressNulls(_suppressableValue)) {
694696
return;
695697
}
696698
if (_nullSerializer != null) {

src/main/java/com/fasterxml/jackson/databind/ser/DefaultSerializerProvider.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -165,11 +165,11 @@ public boolean includeFilterSuppressNulls(Object filter) throws JsonMappingExcep
165165
// But just in case, let's handle unexpected (from our perspective) problems explicitly
166166
try {
167167
return filter.equals(null);
168-
} catch (Throwable t) {
168+
} catch (Exception e) {
169169
String msg = String.format(
170170
"Problem determining whether filter of type '%s' should filter out `null` values: (%s) %s",
171-
filter.getClass().getName(), t.getClass().getName(), ClassUtil.exceptionMessage(t));
172-
reportBadDefinition(filter.getClass(), msg, t);
171+
filter.getClass().getName(), e.getClass().getName(), ClassUtil.exceptionMessage(e));
172+
reportBadDefinition(filter.getClass(), msg, e);
173173
return false; // never gets here
174174
}
175175
}

src/test/java/com/fasterxml/jackson/databind/ser/filter/JsonIncludeCustomTest.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,9 @@ public void testBrokenFilter() throws Exception
132132
String json = MAPPER.writeValueAsString(new BrokenBean(null));
133133
fail("Should not pass, produced: "+json);
134134
} catch (JsonMappingException e) {
135-
verifyException(e, "while trying to invoke the method java.lang.Object.toString() of a null object loaded from local variable 'other'");
135+
// 20-Jun-2022, tatu: Actual message seems to vary across JDKs...
136+
verifyException(e, "Problem determining whether filter");
137+
verifyException(e, "should filter out `null` values");
136138
}
137139
}
138140
}

0 commit comments

Comments
 (0)