Skip to content

Commit fb79454

Browse files
JooHyukKimcowtowncoder
authored andcommitted
Create RecordJsonCreatorAndJsonValue4724Test.java (#4726)
1 parent c6c92b0 commit fb79454

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package com.fasterxml.jackson.databind.tofix;
2+
3+
import com.fasterxml.jackson.annotation.JsonCreator;
4+
import com.fasterxml.jackson.annotation.JsonValue;
5+
import com.fasterxml.jackson.databind.testutil.DatabindTestUtil;
6+
import com.fasterxml.jackson.databind.testutil.failure.JacksonTestFailureExpected;
7+
8+
import org.junit.jupiter.api.Test;
9+
10+
// [databind#4724] Deserialization behavior change with Java Records, JsonCreator and JsonValue between 2.17.2 => 2.18.0
11+
public class RecordJsonCreatorAndJsonValue4724Test
12+
extends DatabindTestUtil
13+
{
14+
15+
public record Something(String value) {
16+
public Something {
17+
if (value == null || value.isEmpty()) {
18+
throw new IllegalArgumentException("Value cannot be null or empty");
19+
}
20+
}
21+
22+
@JsonCreator
23+
public static Something of(String value) {
24+
if (value.isEmpty()) {
25+
return null;
26+
}
27+
return new Something(value);
28+
}
29+
30+
@Override
31+
@JsonValue
32+
public String toString() {
33+
return value;
34+
}
35+
}
36+
37+
@JacksonTestFailureExpected
38+
@Test
39+
void deserialization() throws Exception {
40+
newJsonMapper().readValue("\"\"", Something.class);
41+
}
42+
43+
}

0 commit comments

Comments
 (0)