Skip to content

Commit dc6ccaf

Browse files
committed
Add a (passing) unit test for #3481.
1 parent c6425c5 commit dc6ccaf

File tree

1 file changed

+38
-1
lines changed

1 file changed

+38
-1
lines changed

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

+38-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import java.util.LinkedHashMap;
44
import java.util.Map;
5+
import java.util.concurrent.atomic.AtomicInteger;
56

67
import com.fasterxml.jackson.annotation.*;
78

@@ -59,6 +60,25 @@ static class BrokenBean {
5960
public BrokenBean(String v) { value = v; }
6061
}
6162

63+
// [databind#3481]
64+
static class CountingFooFilter {
65+
public final static AtomicInteger counter = new AtomicInteger(0);
66+
67+
@Override
68+
public boolean equals(Object other) {
69+
counter.incrementAndGet();
70+
return "foo".equals(other);
71+
}
72+
}
73+
74+
static class CountingFooBean {
75+
@JsonInclude(value=JsonInclude.Include.CUSTOM,
76+
valueFilter=CountingFooFilter.class)
77+
public String value;
78+
79+
public CountingFooBean(String v) { value = v; }
80+
}
81+
6282
/*
6383
/**********************************************************
6484
/* Test methods, success
@@ -79,10 +99,27 @@ public void testCustomFilterWithMap() throws Exception
7999
.add("a", "1")
80100
.add("b", "foo")
81101
.add("c", "2");
82-
102+
83103
assertEquals(a2q("{'stuff':{'a':'1','c':'2'}}"), MAPPER.writeValueAsString(input));
84104
}
85105

106+
// [databind#3481]
107+
public void testRepeatedCalls() throws Exception
108+
{
109+
CountingFooFilter.counter.set(0);
110+
111+
assertEquals(a2q("{'value':'x'}"),
112+
MAPPER.writeValueAsString(new CountingFooBean("x")));
113+
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());
117+
assertEquals("{}", MAPPER.writeValueAsString(new CountingFooBean("foo")));
118+
119+
// but beyond initial extra call, as expected
120+
assertEquals(3, CountingFooFilter.counter.get());
121+
}
122+
86123
/*
87124
/**********************************************************
88125
/* Test methods, fail handling

0 commit comments

Comments
 (0)