|
1 | 1 | package com.fasterxml.jackson.databind.introspect;
|
2 | 2 |
|
| 3 | +import java.util.Objects; |
| 4 | + |
3 | 5 | import com.fasterxml.jackson.annotation.*;
|
4 | 6 | import com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility;
|
| 7 | + |
5 | 8 | import com.fasterxml.jackson.core.*;
|
| 9 | + |
6 | 10 | import com.fasterxml.jackson.databind.*;
|
7 | 11 | import com.fasterxml.jackson.databind.introspect.VisibilityChecker;
|
8 | 12 |
|
@@ -35,13 +39,84 @@ public void setValue(int x) {
|
35 | 39 | }
|
36 | 40 | }
|
37 | 41 |
|
| 42 | + // [databind#1947] |
| 43 | + static class Entity1947 { |
| 44 | + public int shouldBeDetected; |
| 45 | + public String shouldNotBeDetected; |
| 46 | + |
| 47 | + @JsonProperty |
| 48 | + public int getShouldBeDetected() { |
| 49 | + return shouldBeDetected; |
| 50 | + } |
| 51 | + |
| 52 | + public void setShouldBeDetected(int shouldBeDetected) { |
| 53 | + this.shouldBeDetected = shouldBeDetected; |
| 54 | + } |
| 55 | + |
| 56 | + public String getShouldNotBeDetected() { |
| 57 | + return shouldNotBeDetected; |
| 58 | + } |
| 59 | + |
| 60 | + public void setShouldNotBeDetected(String shouldNotBeDetected) { |
| 61 | + this.shouldNotBeDetected = shouldNotBeDetected; |
| 62 | + } |
| 63 | + } |
| 64 | + |
| 65 | + // For [databind#2789] |
| 66 | + |
| 67 | + @SuppressWarnings("unused") |
| 68 | + @JsonAutoDetect( |
| 69 | + getterVisibility = JsonAutoDetect.Visibility.NONE, |
| 70 | + creatorVisibility = JsonAutoDetect.Visibility.NONE, |
| 71 | + isGetterVisibility = JsonAutoDetect.Visibility.NONE, |
| 72 | + fieldVisibility = JsonAutoDetect.Visibility.NONE, |
| 73 | + setterVisibility = JsonAutoDetect.Visibility.NONE) |
| 74 | + @JsonTypeInfo( |
| 75 | + use = JsonTypeInfo.Id.NAME, |
| 76 | + include = JsonTypeInfo.As.PROPERTY, |
| 77 | + property = "type", |
| 78 | + visible = true) |
| 79 | + @JsonSubTypes({ |
| 80 | + @JsonSubTypes.Type(name = "CLASS_A", value = DataClassA.class) |
| 81 | + }) |
| 82 | + private static abstract class DataParent2789 { |
| 83 | + |
| 84 | + @JsonProperty("type") |
| 85 | + @JsonTypeId |
| 86 | + private final DataType2789 type; |
| 87 | + |
| 88 | + DataParent2789() { |
| 89 | + super(); |
| 90 | + this.type = null; |
| 91 | + } |
| 92 | + |
| 93 | + DataParent2789(final DataType2789 type) { |
| 94 | + super(); |
| 95 | + this.type = Objects.requireNonNull(type); |
| 96 | + } |
| 97 | + |
| 98 | + public DataType2789 getType() { |
| 99 | + return this.type; |
| 100 | + } |
| 101 | + } |
| 102 | + |
| 103 | + private static final class DataClassA extends DataParent2789 { |
| 104 | + DataClassA() { |
| 105 | + super(DataType2789.CLASS_A); |
| 106 | + } |
| 107 | + } |
| 108 | + |
| 109 | + private enum DataType2789 { |
| 110 | + CLASS_A; |
| 111 | + } |
| 112 | + |
38 | 113 | /*
|
39 | 114 | /********************************************************
|
40 | 115 | /* Unit tests
|
41 | 116 | /********************************************************
|
42 | 117 | */
|
43 | 118 |
|
44 |
| - private final ObjectMapper MAPPER = new ObjectMapper(); |
| 119 | + private final ObjectMapper MAPPER = newJsonMapper(); |
45 | 120 |
|
46 | 121 | public void testPrivateCtor() throws Exception
|
47 | 122 | {
|
@@ -101,4 +176,28 @@ public void testVisibilityConfigOverridesForDeser() throws Exception
|
101 | 176 | Feature1347DeserBean result = mapper.readValue(JSON, Feature1347DeserBean.class);
|
102 | 177 | assertEquals(3, result.value);
|
103 | 178 | }
|
| 179 | + |
| 180 | + // [databind#1947] |
| 181 | + public void testDisablingAll() throws Exception |
| 182 | + { |
| 183 | + ObjectMapper mapper = jsonMapperBuilder() |
| 184 | + .disable(MapperFeature.AUTO_DETECT_SETTERS) |
| 185 | + .disable(MapperFeature.AUTO_DETECT_FIELDS) |
| 186 | + .disable(MapperFeature.AUTO_DETECT_GETTERS) |
| 187 | + .disable(MapperFeature.AUTO_DETECT_CREATORS) |
| 188 | + .disable(MapperFeature.AUTO_DETECT_IS_GETTERS) |
| 189 | + .build(); |
| 190 | + String json = mapper.writeValueAsString(new Entity1947()); |
| 191 | + JsonNode n = mapper.readTree(json); |
| 192 | + assertEquals(1, n.size()); |
| 193 | + assertTrue(n.has("shouldBeDetected")); |
| 194 | + assertFalse(n.has("shouldNotBeDetected")); |
| 195 | + } |
| 196 | + |
| 197 | + // [databind#2789] |
| 198 | + public void testAnnotatedFieldIssue2789() throws Exception { |
| 199 | + final String json = MAPPER.writeValueAsString(new DataClassA()); |
| 200 | + final DataParent2789 copy = MAPPER.readValue(json, DataParent2789.class); |
| 201 | + assertEquals(DataType2789.CLASS_A, copy.getType()); |
| 202 | + } |
104 | 203 | }
|
0 commit comments