|
| 1 | +package com.fasterxml.jackson.databind.jsonschema; |
| 2 | + |
| 3 | +import java.util.*; |
| 4 | + |
| 5 | +import org.junit.jupiter.api.Test; |
| 6 | + |
| 7 | +import com.fasterxml.jackson.annotation.*; |
| 8 | +import com.fasterxml.jackson.databind.*; |
| 9 | +import com.fasterxml.jackson.databind.jsonFormatVisitors.*; |
| 10 | +import com.fasterxml.jackson.databind.testutil.DatabindTestUtil; |
| 11 | + |
| 12 | +import static org.junit.jupiter.api.Assertions.*; |
| 13 | + |
| 14 | +// [databind#5393] @JsonAnyGetter property gets included in generated schema since 2.19.0 |
| 15 | +public class FormatVisitor5393Test |
| 16 | + extends DatabindTestUtil |
| 17 | +{ |
| 18 | + static class TestJsonIgnoredProperties |
| 19 | + { |
| 20 | + @JsonIgnore |
| 21 | + public String ignoredProp; |
| 22 | + |
| 23 | + public String normalProperty; |
| 24 | + |
| 25 | + @JsonProperty("renamedProperty") |
| 26 | + public String someProperty; |
| 27 | + |
| 28 | + // [databind#5393] |
| 29 | + @JsonAnyGetter |
| 30 | + public Map<String, Object> anyProperties() { |
| 31 | + return new TreeMap<>(); |
| 32 | + } |
| 33 | + } |
| 34 | + |
| 35 | + private final ObjectMapper MAPPER = newJsonMapper(); |
| 36 | + |
| 37 | + // [databind#5393]: regression wrt `@JsonAnyGetter` |
| 38 | + @Test |
| 39 | + public void ignoreExplicitlyIgnoredAndAnyGetter() throws Exception { |
| 40 | + final TreeSet<String> expected = new TreeSet<>(); |
| 41 | + expected.add("normalProperty"); |
| 42 | + expected.add("renamedProperty"); |
| 43 | + |
| 44 | + final Set<String> actual = new TreeSet<>(); |
| 45 | + MAPPER.acceptJsonFormatVisitor(TestJsonIgnoredProperties.class, |
| 46 | + new JsonFormatVisitorWrapper.Base() { |
| 47 | + @Override |
| 48 | + public JsonObjectFormatVisitor expectObjectFormat(JavaType type) { |
| 49 | + return new JsonObjectFormatVisitor.Base() { |
| 50 | + @Override |
| 51 | + public void property(BeanProperty prop) { |
| 52 | + actual.add(prop.getName()); |
| 53 | + } |
| 54 | + |
| 55 | + @Override |
| 56 | + public void property(String name, JsonFormatVisitable handler, JavaType propertyTypeHint) { |
| 57 | + actual.add(name); |
| 58 | + } |
| 59 | + |
| 60 | + @Override |
| 61 | + public void optionalProperty(BeanProperty prop) { |
| 62 | + actual.add(prop.getName()); |
| 63 | + } |
| 64 | + |
| 65 | + @Override |
| 66 | + public void optionalProperty(String name, JsonFormatVisitable handler, JavaType propertyTypeHint) { |
| 67 | + actual.add(name); |
| 68 | + } |
| 69 | + }; |
| 70 | + } |
| 71 | + }); |
| 72 | + |
| 73 | + assertEquals(expected, actual); |
| 74 | + } |
| 75 | +} |
0 commit comments