|
| 1 | +package tools.jackson.databind.misc; |
| 2 | + |
| 3 | +import java.io.StringReader; |
| 4 | +import java.io.ByteArrayInputStream; |
| 5 | +import java.nio.charset.StandardCharsets; |
| 6 | + |
| 7 | +import org.junit.jupiter.api.Test; |
| 8 | + |
| 9 | +import tools.jackson.databind.ObjectMapper; |
| 10 | +import tools.jackson.databind.testutil.DatabindTestUtil; |
| 11 | + |
| 12 | +import static org.junit.jupiter.api.Assertions.assertEquals; |
| 13 | + |
| 14 | +// [databind#5372]: Property name mismatch problem, |
| 15 | +// caused by [core#1491]; verify that databind usage fixed as well |
| 16 | +public class PropertyMismatch5372Test extends DatabindTestUtil |
| 17 | +{ |
| 18 | + static class TestObject5372 { |
| 19 | + private String aaaabbbbcccc; |
| 20 | + private String aaaabbbbcccc2; |
| 21 | + |
| 22 | + public String getAaaabbbbcccc2() { |
| 23 | + return aaaabbbbcccc2; |
| 24 | + } |
| 25 | + |
| 26 | + public void setAaaabbbbcccc2(String aaaabbbbcccc2) { |
| 27 | + this.aaaabbbbcccc2 = aaaabbbbcccc2; |
| 28 | + } |
| 29 | + |
| 30 | + public String getAaaabbbbcccc() { |
| 31 | + return aaaabbbbcccc; |
| 32 | + } |
| 33 | + |
| 34 | + public void setAaaabbbbcccc(String aaaabbbbcccc) { |
| 35 | + this.aaaabbbbcccc = aaaabbbbcccc; |
| 36 | + } |
| 37 | + } |
| 38 | + |
| 39 | + private final String KEY_1 = "aaaabbbbcccc"; |
| 40 | + private final String KEY_2 = "aaaabbbbcccc2"; |
| 41 | + |
| 42 | + private final String DOC_5372 = """ |
| 43 | +{ |
| 44 | +"%s": "v3", |
| 45 | +"%s": "v4" |
| 46 | +} |
| 47 | +""".formatted(KEY_1, KEY_2); |
| 48 | + |
| 49 | + private final ObjectMapper MAPPER = newJsonMapper(); |
| 50 | + |
| 51 | + @Test |
| 52 | + void testIssue5372Bytes() throws Exception |
| 53 | + { |
| 54 | + final byte[] bytes = DOC_5372.getBytes(StandardCharsets.UTF_8); |
| 55 | + _assert5372(MAPPER.readValue(bytes, TestObject5372.class)); |
| 56 | + _assert5372(MAPPER.readValue(new ByteArrayInputStream(bytes), TestObject5372.class)); |
| 57 | + } |
| 58 | + |
| 59 | + @Test |
| 60 | + void testIssue5372Chars() throws Exception |
| 61 | + { |
| 62 | + _assert5372(MAPPER.readValue(DOC_5372, TestObject5372.class)); |
| 63 | + _assert5372(MAPPER.readValue(new StringReader(DOC_5372), TestObject5372.class)); |
| 64 | + } |
| 65 | + |
| 66 | + private void _assert5372(TestObject5372 result) { |
| 67 | + assertEquals("v3", result.getAaaabbbbcccc()); |
| 68 | + assertEquals("v4", result.getAaaabbbbcccc2()); |
| 69 | + } |
| 70 | +} |
0 commit comments