-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Closed
Labels
2.18Issues planned at 2.18 or laterIssues planned at 2.18 or laterRecordIssue related to JDK17 java.lang.Record supportIssue related to JDK17 java.lang.Record supporthas-failing-testIndicates that there exists a test case (under `failing/`) to reproduce the issueIndicates that there exists a test case (under `failing/`) to reproduce the issue
Milestone
Description
Search before asking
- I searched in the issues and found nothing similar.
Describe the bug
Using both JsonCreator and JsonValue annotations with Java Records makes ObjectMapper seemingly skip single-arg static JsonCreator method and try to contract instance directly. I couldn't find any hint that this was a planned change.
Version Information
2.18.0
Reproduction
The following code works with 2.17.2, but fails with 2.18.0
@Test
void deserialization() throws Exception {
new ObjectMapper().readValue("\"\"", Something.class);
}
public record Something(String value) {
public Something {
if (value == null || value.isEmpty()) {
throw new IllegalArgumentException("Value cannot be null or empty");
}
}
@JsonCreator
public static Something of(String value) {
if (value.isEmpty()) {
return null;
}
return new Something(value);
}
@Override
@JsonValue
public String toString() {
return value;
}
}
Removing JsonValue annotation makes deserialization to work again.
Expected behavior
No response
Additional context
No response
ianfp
Metadata
Metadata
Assignees
Labels
2.18Issues planned at 2.18 or laterIssues planned at 2.18 or laterRecordIssue related to JDK17 java.lang.Record supportIssue related to JDK17 java.lang.Record supporthas-failing-testIndicates that there exists a test case (under `failing/`) to reproduce the issueIndicates that there exists a test case (under `failing/`) to reproduce the issue