Skip to content

Commit 383ca82

Browse files
committed
Add a verification test for #1060
1 parent 8840c35 commit 383ca82

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

release-notes/VERSION-2.x

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ Project: jackson-databind
161161
#1029: Add a way to define property name aliases
162162
#1035: `@JsonAnySetter` assumes key of `String`, does not consider declared type.
163163
(reported by Michael F)
164+
#1060: Allow use of `@JsonIgnoreProperties` for POJO-valued arrays, `Collection`s
164165
#1106: Add `MapperFeature.ALLOW_COERCION_OF_SCALARS` for enabling/disabling coercions
165166
#1284: Make `StdKeySerializers` use new `JsonGenerator.writeFieldId()` for `int`/`long` keys
166167
#1320: Add `ObjectNode.put(String, BigInteger)`

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

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,25 @@ static class MapWrapper {
6363
}
6464
}
6565

66+
// for [databind#1060]
67+
static class IgnoreForListValuesXY {
68+
@JsonIgnoreProperties({ "x" })
69+
public List<XY> coordinates;
70+
71+
public IgnoreForListValuesXY() {
72+
coordinates = Arrays.asList(new XY());
73+
}
74+
}
75+
76+
static class IgnoreForListValuesXYZ {
77+
@JsonIgnoreProperties({ "y" })
78+
public List<XYZ> coordinates;
79+
80+
public IgnoreForListValuesXYZ() {
81+
coordinates = Arrays.asList(new XYZ());
82+
}
83+
}
84+
6685
/*
6786
/****************************************************************
6887
/* Unit tests
@@ -129,4 +148,17 @@ public void testIgnoreViaConfigOverride() throws Exception
129148
.setIgnorals(JsonIgnoreProperties.Value.forIgnoredProperties("x"));
130149
assertEquals("{\"y\":3}", mapper.writeValueAsString(new Point(2, 3)));
131150
}
151+
152+
// for [databind#1060]
153+
// Ensure that `@JsonIgnoreProperties` applies to POJOs within lists, too
154+
public void testIgnoreForListValues() throws Exception
155+
{
156+
// should apply to elements
157+
assertEquals(aposToQuotes("{'coordinates':[{'y':2}]}"),
158+
MAPPER.writeValueAsString(new IgnoreForListValuesXY()));
159+
160+
// and combine values too
161+
assertEquals(aposToQuotes("{'coordinates':[{'z':3}]}"),
162+
MAPPER.writeValueAsString(new IgnoreForListValuesXYZ()));
163+
}
132164
}

0 commit comments

Comments
 (0)