Skip to content

Commit b50eb09

Browse files
committed
Fix #2118 and #2283
1 parent 2933c6a commit b50eb09

File tree

6 files changed

+47
-20
lines changed

6 files changed

+47
-20
lines changed

release-notes/CREDITS-2.x

+10
Original file line numberDiff line numberDiff line change
@@ -1115,6 +1115,16 @@ Nate Bauernfeind (nbauernfeind@github)
11151115
* Reported #2091: `ReferenceType` does not expose valid containedType
11161116
(2.12.0)
11171117

1118+
Xiang Zhang (zhangyangyu@github)
1119+
* Reported #2118: `JsonProperty.Access.READ_ONLY` does not work with "getter-as-setter"
1120+
Collections
1121+
(2.12.0)
1122+
1123+
Yona Appletree (Yona-Appletree@github)
1124+
* Reported #2283: `JsonProperty.Access.READ_ONLY` fails with collections when a
1125+
property name is specified
1126+
(2.12.0)
1127+
11181128
David Bidorff (bidorffOL@github)
11191129
* Reported, contributed fix for #2719: `FAIL_ON_IGNORED_PROPERTIES` does not throw
11201130
on `READONLY` properties with an explicit name

release-notes/VERSION-2.x

+4
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ Project: jackson-databind
1515
(reported by Incara@github)
1616
#2091: `ReferenceType` does not expose valid containedType
1717
(reported by Nate B)
18+
#2118: `JsonProperty.Access.READ_ONLY` does not work with "getter-as-setter" `Collection`s
19+
(reported by Xiang Z)
20+
#2283: `JsonProperty.Access.READ_ONLY` fails with collections when a property name is specified
21+
(reported by Yona A)
1822
#2675: Support use of `Void` valued properties (`MapperFeature.ALLOW_VOID_VALUED_PROPERTIES`)
1923
#2683: Explicitly fail (de)serialization of `java.time.*` types in absence of
2024
registered custom (de)serializers

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

+17-9
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
import com.fasterxml.jackson.annotation.JacksonInject;
77
import com.fasterxml.jackson.annotation.JsonCreator;
8-
import com.fasterxml.jackson.annotation.JsonProperty;
98

109
import com.fasterxml.jackson.databind.*;
1110

@@ -872,12 +871,20 @@ protected void _renameProperties(Map<String, POJOPropertyBuilder> props)
872871
old.addAll(prop);
873872
}
874873
// replace the creatorProperty too, if there is one
875-
_updateCreatorProperty(prop, _creatorProperties);
876-
// [databind#2001]: New name of property was ignored previously? Remove from ignored
877-
// 01-May-2018, tatu: I have a feeling this will need to be revisited at some point,
878-
// to avoid removing some types of removals, possibly. But will do for now.
879-
if (_ignoredPropertyNames != null) {
880-
_ignoredPropertyNames.remove(name);
874+
if (_updateCreatorProperty(prop, _creatorProperties)) {
875+
// [databind#2001]: New name of property was ignored previously? Remove from ignored
876+
// 01-May-2018, tatu: I have a feeling this will need to be revisited at some point,
877+
// to avoid removing some types of removals, possibly. But will do for now.
878+
879+
// 16-May-2020, tatu: ... and so the day came, [databind#2118] failed
880+
// when explicit rename added to ignorals (for READ_ONLY) was suddenly
881+
// removed from ignoral list. So, added a guard statement above so that
882+
// ignoral is ONLY removed if there was matching creator property.
883+
//
884+
// Chances are this is not the last tweak we need but... that bridge then etc
885+
if (_ignoredPropertyNames != null) {
886+
_ignoredPropertyNames.remove(name);
887+
}
881888
}
882889
}
883890
}
@@ -1174,16 +1181,17 @@ private PropertyNamingStrategy _findNamingStrategy()
11741181
_config.canOverrideAccessModifiers());
11751182
}
11761183

1177-
protected void _updateCreatorProperty(POJOPropertyBuilder prop, List<POJOPropertyBuilder> creatorProperties) {
1184+
protected boolean _updateCreatorProperty(POJOPropertyBuilder prop, List<POJOPropertyBuilder> creatorProperties) {
11781185

11791186
if (creatorProperties != null) {
11801187
final String intName = prop.getInternalName();
11811188
for (int i = 0, len = creatorProperties.size(); i < len; ++i) {
11821189
if (creatorProperties.get(i).getInternalName().equals(intName)) {
11831190
creatorProperties.set(i, prop);
1184-
break;
1191+
return true;
11851192
}
11861193
}
11871194
}
1195+
return false;
11881196
}
11891197
}

src/test/java/com/fasterxml/jackson/databind/deser/ReadOnlyDeser2719Test.java renamed to src/test/java/com/fasterxml/jackson/databind/deser/ReadOnlyDeserFailOnUnknown2719Test.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
import com.fasterxml.jackson.databind.*;
66

7-
public class ReadOnlyDeser2719Test extends BaseMapTest
7+
public class ReadOnlyDeserFailOnUnknown2719Test extends BaseMapTest
88
{
99
// [databind#2719]
1010
static class UserWithReadOnly {

src/test/java/com/fasterxml/jackson/failing/PropertyAccessReadOnly2118Test.java renamed to src/test/java/com/fasterxml/jackson/databind/deser/ReadOnlyListDeser2118Test.java

+13-8
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
1-
package com.fasterxml.jackson.failing;
1+
package com.fasterxml.jackson.databind.deser;
22

33
import java.util.*;
44

55
import com.fasterxml.jackson.annotation.*;
66

77
import com.fasterxml.jackson.databind.*;
88

9-
public class PropertyAccessReadOnly2118Test extends BaseMapTest
9+
public class ReadOnlyListDeser2118Test extends BaseMapTest
1010
{
1111
// [databind#2118]
1212
static class SecurityGroup {
13-
14-
private List<SecurityGroupRule> securityGroupRules;
13+
List<SecurityGroupRule> securityGroupRules;
1514

1615
public SecurityGroup() {
1716
this.securityGroupRules = new ArrayList<>();
@@ -40,15 +39,21 @@ public String getId() {
4039
public void setId(String id) {
4140
this.id = id;
4241
}
42+
43+
@Override
44+
public String toString() {
45+
return "{SecurityGroupRule '"+id+"'}";
46+
}
4347
}
4448

49+
private final ObjectMapper mapper = newJsonMapper();
50+
4551
// [databind#2118]
4652
public void testAccessReadOnly() throws Exception {
47-
String data ="{\"security_group_rules\": [{\"id\": \"id1\"}, {\"id\": \"id2\"}, {\"id\": \"id3\"}, {\"id\": \"id4\"}]}";
48-
ObjectMapper mapper = new ObjectMapper();
49-
// This would work around the issue:
53+
String data ="{\"security_group_rules\": [{\"id\": \"id1\"}]}";
54+
// This would work around the issue:
5055
// mapper.disable(MapperFeature.USE_GETTERS_AS_SETTERS);
5156
SecurityGroup sg = mapper.readValue(data, SecurityGroup.class);
52-
System.out.println(mapper.writeValueAsString(sg));
57+
assertEquals(Collections.emptyList(), sg.securityGroupRules);
5358
}
5459
}

src/test/java/com/fasterxml/jackson/failing/ReadOnlyList2283Test.java renamed to src/test/java/com/fasterxml/jackson/databind/deser/ReadOnlyListDeser2283Test.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.fasterxml.jackson.failing;
1+
package com.fasterxml.jackson.databind.deser;
22

33
import java.util.*;
44

@@ -7,7 +7,7 @@
77
import com.fasterxml.jackson.databind.*;
88

99
// [databind#2283]: ignore read-only Lists even if "getter-as-setter" enabled
10-
public class ReadOnlyList2283Test
10+
public class ReadOnlyListDeser2283Test
1111
extends BaseMapTest
1212
{
1313
static class RenamedToSameOnGetter {

0 commit comments

Comments
 (0)