Skip to content

Commit

Permalink
Merge branch '2.13' into 2.14
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed May 7, 2022
2 parents 50f3789 + ba8683f commit 9556e32
Showing 1 changed file with 42 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.util.LinkedHashMap;
import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger;

import com.fasterxml.jackson.annotation.*;

Expand Down Expand Up @@ -59,6 +60,25 @@ static class BrokenBean {
public BrokenBean(String v) { value = v; }
}

// [databind#3481]
static class CountingFooFilter {
public final static AtomicInteger counter = new AtomicInteger(0);

@Override
public boolean equals(Object other) {
counter.incrementAndGet();
return "foo".equals(other);
}
}

static class CountingFooBean {
@JsonInclude(value=JsonInclude.Include.CUSTOM,
valueFilter=CountingFooFilter.class)
public String value;

public CountingFooBean(String v) { value = v; }
}

/*
/**********************************************************
/* Test methods, success
Expand All @@ -79,10 +99,31 @@ public void testCustomFilterWithMap() throws Exception
.add("a", "1")
.add("b", "foo")
.add("c", "2");

assertEquals(a2q("{'stuff':{'a':'1','c':'2'}}"), MAPPER.writeValueAsString(input));
}

// [databind#3481]
public void testRepeatedCalls() throws Exception
{
CountingFooFilter.counter.set(0);

assertEquals(a2q("{'value':'x'}"),
MAPPER.writeValueAsString(new CountingFooBean("x")));

// 06-May-2022, tatu: Maybe surprisingly, we get TWO calls; first one to
// see if `null`s are to be filtered, second time for "real" call
assertEquals(2, CountingFooFilter.counter.get());
assertEquals("{}", MAPPER.writeValueAsString(new CountingFooBean("foo")));

// but beyond initial extra call, as expected
assertEquals(3, CountingFooFilter.counter.get());

// except filter will NOT be called again for `null`s, as per [databind#3481]
assertEquals(a2q("{'value':null}"), MAPPER.writeValueAsString(new CountingFooBean(null)));
assertEquals(3, CountingFooFilter.counter.get());
}

/*
/**********************************************************
/* Test methods, fail handling
Expand Down

0 comments on commit 9556e32

Please sign in to comment.