Skip to content

Commit 6ad9dea

Browse files
committed
Merge branch '2.19'
2 parents 2f35cfc + a4c82c8 commit 6ad9dea

File tree

4 files changed

+16
-6
lines changed

4 files changed

+16
-6
lines changed

release-notes/VERSION-2.x

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ Project: jackson-databind
6262
fails on JDK 17+
6363
#4997: `ObjectNode` put methods should do null check for key
6464
#5014: Add `java.lang.Runnable` as unsafe base type in `DefaultBaseTypeLimitingValidator`
65+
#5020: Support new `@JsonProperty.isRequired` for overridable definition of "required-ness"
6566
6667
2.18.3 (28-Feb-2025)
6768

src/main/java/tools/jackson/databind/introspect/JacksonAnnotationIntrospector.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,16 @@ public Boolean hasRequiredMarker(MapperConfig<?> config, AnnotatedMember m)
419419
{
420420
JsonProperty ann = _findAnnotation(m, JsonProperty.class);
421421
if (ann != null) {
422-
return ann.required();
422+
// 11-Mar-2025, tatu: [databind#5020] Support new "isRequired" annotation
423+
OptBoolean required = ann.isRequired();
424+
if (required != OptBoolean.DEFAULT) {
425+
return required.asBoolean();
426+
}
427+
// 11-Mar-2025, tatu: Further, in Jackson 3.0 we will now consider legacy
428+
// property ONLY IF SET TO TRUE (i.e. "false" means "use defaults"
429+
if (ann.required()) {
430+
return Boolean.TRUE;
431+
}
423432
}
424433
return null;
425434
}

src/test/java/tools/jackson/databind/deser/creators/RequiredCreatorTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ static class FascistPoint {
2020

2121
@JsonCreator
2222
public FascistPoint(@JsonProperty(value="x", required=true) Integer x,
23-
@JsonProperty(value="y", required=false) Integer y)
23+
@JsonProperty(value="y", isRequired=OptBoolean.FALSE) Integer y)
2424
{
2525
this.x = x;
2626
this.y = y;
@@ -34,7 +34,7 @@ static class LoginUserResponse {
3434
private String userType;
3535

3636
@JsonCreator
37-
public LoginUserResponse(@JsonProperty(value = "otp", required = true) String otp,
37+
public LoginUserResponse(@JsonProperty(value = "otp", isRequired = OptBoolean.TRUE) String otp,
3838
@JsonProperty(value = "userType", required = true) String userType) {
3939
this.otp = otp;
4040
this.userType = userType;

src/test/java/tools/jackson/databind/introspect/JacksonAnnotationIntrospectorTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,9 +135,9 @@ public String[] findEnumValues(MapperConfig<?> config, AnnotatedClass annotatedC
135135
}
136136

137137
/*
138-
/**********************************************************
139-
/* Unit tests
140-
/**********************************************************
138+
/**********************************************************************
139+
/* Test methods
140+
/**********************************************************************
141141
*/
142142

143143
/**

0 commit comments

Comments
 (0)