77import com .fasterxml .jackson .annotation .*;
88
99import com .fasterxml .jackson .databind .BaseMapTest ;
10+ import com .fasterxml .jackson .databind .JsonMappingException ;
1011import com .fasterxml .jackson .databind .ObjectMapper ;
11- import com .fasterxml .jackson .databind .exc .InvalidDefinitionException ;
1212
1313// Tests for [databind#888]
1414public class JsonIncludeCustomTest extends BaseMapTest
@@ -110,16 +110,12 @@ public void testRepeatedCalls() throws Exception
110110
111111 assertEquals (a2q ("{'value':'x'}" ),
112112 MAPPER .writeValueAsString (new CountingFooBean ("x" )));
113+ assertEquals (1 , CountingFooFilter .counter .get ());
113114
114- // 06-May-2022, tatu: Maybe surprisingly, we get TWO calls; first one to
115- // see if `null`s are to be filtered, second time for "real" call
116- assertEquals (2 , CountingFooFilter .counter .get ());
117115 assertEquals ("{}" , MAPPER .writeValueAsString (new CountingFooBean ("foo" )));
116+ assertEquals (2 , CountingFooFilter .counter .get ());
118117
119- // but beyond initial extra call, as expected
120- assertEquals (3 , CountingFooFilter .counter .get ());
121-
122- // except filter will NOT be called again for `null`s, as per [databind#3481]
118+ // except filter will be called again for `null`s, as per [databind#3481]
123119 assertEquals (a2q ("{'value':null}" ), MAPPER .writeValueAsString (new CountingFooBean (null )));
124120 assertEquals (3 , CountingFooFilter .counter .get ());
125121 }
@@ -133,11 +129,10 @@ public void testRepeatedCalls() throws Exception
133129 public void testBrokenFilter () throws Exception
134130 {
135131 try {
136- String json = MAPPER .writeValueAsString (new BrokenBean ("foo" ));
132+ String json = MAPPER .writeValueAsString (new BrokenBean (null ));
137133 fail ("Should not pass, produced: " +json );
138- } catch (InvalidDefinitionException e ) {
139- verifyException (e , "Problem determining whether filter of type" );
140- verifyException (e , "filter out `null`" );
134+ } 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'" );
141136 }
142137 }
143138}
0 commit comments