Skip to content

Commit ebf0732

Browse files
committed
Minor post-merge cleanup
1 parent 86350f5 commit ebf0732

File tree

5 files changed

+53
-31
lines changed

5 files changed

+53
-31
lines changed

release-notes/CREDITS-2.x

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1178,6 +1178,10 @@ Baptiste Pernet (sp4ce@github)
11781178
of `@JsonIgnoreProperties`)
11791179
(2.12.0)
11801180
1181+
Dominik Krebhan (dominikrebhan@github)
1182+
* Contributed #1458: `@JsonAnyGetter` should be allowed on a field
1183+
(2.12.0)
1184+
11811185
Patrick Jungermann (pjungermann@github)
11821186
* Requested #1852: Allow case insensitive deserialization of String value into
11831187
`boolean`/`Boolean` (esp for Excel)

release-notes/VERSION-2.x

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ Project: jackson-databind
77

88
2.12.0-rc2 (not yet released)
99

10+
#1458: `@JsonAnyGetter` should be allowed on a field
11+
(contributed by Dominik K)
1012
#2775: Disabling `FAIL_ON_INVALID_SUBTYPE` breaks polymorphic deserialization of Enums
1113
(reported by holgerknoche@github)
1214
#2878: Revert change initially made to fix #2805: change in signature

src/main/java/com/fasterxml/jackson/databind/introspect/POJOPropertiesCollector.java

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,18 @@ public AnnotatedMember getJsonValueAccessor()
214214
}
215215

216216
/**
217-
* @since 2.12
217+
* Alias for {@link #getAnyGetterMethod()}.
218+
*
219+
* @deprecated Since 2.12 use separate {@link #getAnyGetterMethod()} and
220+
* {@link #getAnyGetterField()}.
221+
*/
222+
@Deprecated // since 2.12
223+
public AnnotatedMember getAnyGetter() {
224+
return getAnyGetterMethod();
225+
}
226+
227+
/**
228+
* @since 2.12 (before only had "getAnyGetter()")
218229
*/
219230
public AnnotatedMember getAnyGetterField()
220231
{
@@ -231,6 +242,9 @@ public AnnotatedMember getAnyGetterField()
231242
return null;
232243
}
233244

245+
/**
246+
* @since 2.12 (before only had "getAnyGetter()")
247+
*/
234248
public AnnotatedMember getAnyGetterMethod()
235249
{
236250
if (!_collected) {
@@ -721,7 +735,7 @@ protected void _addSetterMethod(Map<String, POJOPropertyBuilder> props,
721735
}
722736
// 27-Dec-2019, tatu: [databind#2527] may need to rename according to field
723737
implName = _checkRenameByField(implName);
724-
boolean ignore = ai != null && ai.hasIgnoreMarker(m);
738+
boolean ignore = (ai != null) && ai.hasIgnoreMarker(m);
725739
_property(props, implName).addSetter(m, pn, nameExplicit, visible, ignore);
726740
}
727741

src/test/java/com/fasterxml/jackson/databind/access/TestAnyGetterAccess.java

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -34,22 +34,6 @@ public void set(String name, String value) {
3434
}
3535
}
3636

37-
static class DynaFieldBean {
38-
public int id;
39-
40-
@JsonAnyGetter
41-
@JsonAnySetter
42-
protected HashMap<String,String> other = new HashMap<String,String>();
43-
44-
public Map<String,String> any() {
45-
return other;
46-
}
47-
48-
public void set(String name, String value) {
49-
other.put(name, value);
50-
}
51-
}
52-
5337
static class PrivateThing
5438
{
5539
@JsonAnyGetter
@@ -81,18 +65,6 @@ public void testDynaBean() throws Exception
8165
assertEquals("Joe", result.other.get("name"));
8266
}
8367

84-
public void testDynaFieldBean() throws Exception
85-
{
86-
DynaFieldBean b = new DynaFieldBean();
87-
b.id = 123;
88-
b.set("name", "Billy");
89-
assertEquals("{\"id\":123,\"name\":\"Billy\"}", MAPPER.writeValueAsString(b));
90-
91-
DynaFieldBean result = MAPPER.readValue("{\"id\":2,\"name\":\"Joe\"}", DynaFieldBean.class);
92-
assertEquals(2, result.id);
93-
assertEquals("Joe", result.other.get("name"));
94-
}
95-
9668
public void testPrivate() throws Exception
9769
{
9870
String json = MAPPER.writeValueAsString(new PrivateThing());

src/test/java/com/fasterxml/jackson/databind/ser/AnyGetterTest.java

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,13 +163,43 @@ public Map<String, String> getProperties() {
163163
@JsonFilter("Bean2592")
164164
static class Bean2592WithFilter extends Bean2592NoAnnotations {}
165165

166+
// [databind#1458]: Allow `@JsonAnyGetter` on fields too
167+
static class DynaFieldBean {
168+
public int id;
169+
170+
@JsonAnyGetter
171+
@JsonAnySetter
172+
protected HashMap<String,String> other = new HashMap<String,String>();
173+
174+
public Map<String,String> any() {
175+
return other;
176+
}
177+
178+
public void set(String name, String value) {
179+
other.put(name, value);
180+
}
181+
}
182+
183+
// [databind#1458]: Allow `@JsonAnyGetter` on fields too
184+
public void testDynaFieldBean() throws Exception
185+
{
186+
DynaFieldBean b = new DynaFieldBean();
187+
b.id = 123;
188+
b.set("name", "Billy");
189+
assertEquals("{\"id\":123,\"name\":\"Billy\"}", MAPPER.writeValueAsString(b));
190+
191+
DynaFieldBean result = MAPPER.readValue("{\"id\":2,\"name\":\"Joe\"}", DynaFieldBean.class);
192+
assertEquals(2, result.id);
193+
assertEquals("Joe", result.other.get("name"));
194+
}
195+
166196
/*
167197
/**********************************************************
168198
/* Test methods
169199
/**********************************************************
170200
*/
171201

172-
private final ObjectMapper MAPPER = new ObjectMapper();
202+
private final ObjectMapper MAPPER = newJsonMapper();
173203

174204
public void testSimpleAnyBean() throws Exception
175205
{

0 commit comments

Comments
 (0)