Skip to content

Commit 4d34006

Browse files
committed
Fix #935
1 parent 2bb770b commit 4d34006

File tree

4 files changed

+15
-8
lines changed

4 files changed

+15
-8
lines changed

release-notes/VERSION

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ Project: jackson-databind
55

66
2.8.7 (not yet released)
77

8-
#1317: '@JsonIgnore' annotation not working with creator properties, serialization
8+
#935: `@JsonProperty(access = Access.READ_ONLY)` - unexpected behaviour
9+
#1317: '@JsonIgnore' annotation not working with creator properties, serializatio
910

1011
2.8.6 (12-Jan-2017)
1112

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import java.util.*;
55

66
import com.fasterxml.jackson.annotation.JsonAnySetter;
7+
import com.fasterxml.jackson.annotation.JsonProperty.Access;
78
import com.fasterxml.jackson.databind.*;
89
import com.fasterxml.jackson.databind.cfg.HandlerInstantiator;
910
import com.fasterxml.jackson.databind.cfg.MapperConfig;
@@ -727,10 +728,14 @@ protected void _removeUnwantedAccessor(Map<String, POJOPropertyBuilder> props)
727728

728729
while (it.hasNext()) {
729730
POJOPropertyBuilder prop = it.next();
730-
prop.removeNonVisible(inferMutators);
731+
// 26-Jan-2017, tatu: [databind#935]: need to denote removal of
732+
Access acc = prop.removeNonVisible(inferMutators);
733+
if (!_forSerialization && (acc == Access.READ_ONLY)) {
734+
_collectIgnorals(prop.getName());
735+
}
731736
}
732737
}
733-
738+
734739
/**
735740
* Helper method called to add explicitly ignored properties to a list
736741
* of known ignored properties; this helps in proper reporting of

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -641,7 +641,7 @@ public void removeIgnored()
641641
* @param inferMutators Whether mutators can be "pulled in" by visible
642642
* accessors or not.
643643
*/
644-
public void removeNonVisible(boolean inferMutators)
644+
public JsonProperty.Access removeNonVisible(boolean inferMutators)
645645
{
646646
/* 07-Jun-2015, tatu: With 2.6, we will allow optional definition
647647
* of explicit access type for property; if not "AUTO", it will
@@ -680,6 +680,7 @@ public void removeNonVisible(boolean inferMutators)
680680
_setters = _removeNonVisible(_setters);
681681
}
682682
}
683+
return acc;
683684
}
684685

685686
/**

src/test/java/com/fasterxml/jackson/failing/ReadWriteOnlyProp935Test.java renamed to src/test/java/com/fasterxml/jackson/databind/deser/ReadOrWriteOnlyTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
package com.fasterxml.jackson.failing;
1+
package com.fasterxml.jackson.databind.deser;
22

33
import com.fasterxml.jackson.annotation.JsonProperty;
44
import com.fasterxml.jackson.databind.*;
55

6-
public class ReadWriteOnlyProp935Test extends BaseMapTest
6+
public class ReadOrWriteOnlyTest extends BaseMapTest
77
{
88
// for [databind#935], verify read/write-only cases
99
static class ReadXWriteY {
@@ -56,7 +56,7 @@ public void setLastName(String n) {
5656
*/
5757

5858
private final ObjectMapper MAPPER = new ObjectMapper();
59-
59+
6060
// [databind#935]
6161
public void testReadOnlyAndWriteOnly() throws Exception
6262
{
@@ -69,7 +69,7 @@ public void testReadOnlyAndWriteOnly() throws Exception
6969
assertEquals(6, result.y);
7070
}
7171

72-
public void testReadOnl935() throws Exception
72+
public void testReadOnly935() throws Exception
7373
{
7474
String json = MAPPER.writeValueAsString(new Pojo935());
7575
Pojo935 result = MAPPER.readValue(json, Pojo935.class);

0 commit comments

Comments
 (0)