Skip to content

Commit 6094f22

Browse files
authored
Fix #4552: change MapperFeature.ALLOW_FINAL_FIELDS_AS_MUTATORS default to false (#4555)
1 parent 92e6a12 commit 6094f22

File tree

3 files changed

+10
-5
lines changed

3 files changed

+10
-5
lines changed

release-notes/VERSION

+1
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ Versions: 3.x (for earlier see VERSION-2.x)
5757
#3601: Change `Optional` deserialization from "absent" value into `null`, from "empty"
5858
#4160: Deprecate `DefaultTyping.EVERYTHING` in `2.x` and remove in `3.0`
5959
#4381: Prevent construction of `null`-valued `JsonNode`s (like `TextNode`)
60+
#4552: Change `MapperFeature.ALLOW_FINAL_FIELDS_AS_MUTATORS` default to `false` for 3.0
6061
- Remove `MappingJsonFactory`
6162
- Add context parameter for `TypeSerializer` contextualization (`forProperty()`)
6263
- Default for `JsonNodeFeature.STRIP_TRAILING_BIGDECIMAL_ZEROES` changed to `false` for 3.0

src/main/java/tools/jackson/databind/MapperFeature.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,9 @@ public enum MapperFeature
7878
* rules; if disabled, such fields are NOT used as mutators except if
7979
* explicitly annotated for such use.
8080
*<p>
81-
* Feature is enabled by default, for backwards compatibility reasons.
81+
* Feature is disabled by default in Jackson 3.x, in 2.x it was enabled by default.
8282
*/
83-
ALLOW_FINAL_FIELDS_AS_MUTATORS(true),
83+
ALLOW_FINAL_FIELDS_AS_MUTATORS(false),
8484

8585
/**
8686
* Feature that determines whether member mutators (fields and

src/test/java/tools/jackson/databind/objectid/ObjectId3838Test.java

+7-3
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ public String result() {
3737

3838
@JsonIdentityInfo(property = "id", generator = ObjectIdGenerators.PropertyGenerator.class)
3939
static class CreatorBased implements ResultGetter {
40-
private final String id;
40+
// NOTE: must NOT be `final` unless `MapperFeature.ALLOW_FINAL_FIELDS_AS_MUTATORS` enabled
41+
private String id;
4142

4243
@JsonCreator
4344
CreatorBased(@JsonProperty(value = "id") String id) {
@@ -66,7 +67,8 @@ public String result() {
6667

6768
@JsonIdentityInfo(property = "id", generator = ObjectIdGenerators.PropertyGenerator.class)
6869
static class StaticFactoryMethodBased implements ResultGetter {
69-
private final String id;
70+
// NOTE: must NOT be `final` unless `MapperFeature.ALLOW_FINAL_FIELDS_AS_MUTATORS` enabled
71+
private String id;
7072

7173
private StaticFactoryMethodBased(String id) {
7274
this.id = id;
@@ -89,7 +91,9 @@ public String result() {
8991

9092
@JsonIdentityInfo(property = "id", generator = ObjectIdGenerators.PropertyGenerator.class)
9193
static class MultiArgConstructorBased implements ResultGetter {
92-
private final String id;
94+
// NOTE: must NOT be `final` unless `MapperFeature.ALLOW_FINAL_FIELDS_AS_MUTATORS` enabled
95+
private String id;
96+
9397
private final int value;
9498

9599
@JsonCreator

0 commit comments

Comments
 (0)