|
| 1 | +package com.fasterxml.jackson.databind.tofix; |
| 2 | + |
| 3 | +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; |
| 4 | +import com.fasterxml.jackson.annotation.JsonIncludeProperties; |
| 5 | +import com.fasterxml.jackson.databind.ObjectMapper; |
| 6 | +import com.fasterxml.jackson.databind.testutil.DatabindTestUtil; |
| 7 | +import com.fasterxml.jackson.databind.testutil.failure.JacksonTestFailureExpected; |
| 8 | +import org.junit.jupiter.api.Test; |
| 9 | + |
| 10 | +import static org.junit.jupiter.api.Assertions.assertEquals; |
| 11 | + |
| 12 | +// [databind#4629] @JsonIncludeProperties & @JsonIgnoreProperties |
| 13 | +// are ignored when deserializing Records |
| 14 | +public class RecordsWithJsonIncludeAndIgnorals4629Test |
| 15 | + extends DatabindTestUtil { |
| 16 | + |
| 17 | + record Id2Name( |
| 18 | + int id, |
| 19 | + String name |
| 20 | + ) { } |
| 21 | + |
| 22 | + record RecordWithInclude4629( |
| 23 | + @JsonIncludeProperties("id") Id2Name child |
| 24 | + ) { } |
| 25 | + |
| 26 | + record RecordWIthIgnore4629( |
| 27 | + @JsonIgnoreProperties("name") Id2Name child |
| 28 | + ) { } |
| 29 | + |
| 30 | + private final ObjectMapper MAPPER = newJsonMapper(); |
| 31 | + |
| 32 | + @JacksonTestFailureExpected |
| 33 | + @Test |
| 34 | + void testJsonInclude4629() |
| 35 | + throws Exception |
| 36 | + { |
| 37 | + RecordWithInclude4629 expected = new RecordWithInclude4629(new Id2Name(123, null)); |
| 38 | + String input = "{\"child\":{\"id\":123,\"name\":\"Bob\"}}"; |
| 39 | + |
| 40 | + RecordWithInclude4629 actual = MAPPER.readValue(input, RecordWithInclude4629.class); |
| 41 | + |
| 42 | + assertEquals(expected, actual); |
| 43 | + } |
| 44 | + |
| 45 | + @JacksonTestFailureExpected |
| 46 | + @Test |
| 47 | + void testJsonIgnore4629() |
| 48 | + throws Exception |
| 49 | + { |
| 50 | + RecordWIthIgnore4629 expected = new RecordWIthIgnore4629(new Id2Name(123, null)); |
| 51 | + String input = "{\"child\":{\"id\":123,\"name\":\"Bob\"}}"; |
| 52 | + |
| 53 | + RecordWIthIgnore4629 actual = MAPPER.readValue(input, RecordWIthIgnore4629.class); |
| 54 | + |
| 55 | + assertEquals(expected, actual); |
| 56 | + } |
| 57 | + |
| 58 | +} |
0 commit comments