|
| 1 | +package tools.jackson.databind.failing; |
| 2 | + |
| 3 | +import com.fasterxml.jackson.annotation.JsonAutoDetect; |
| 4 | +import com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility; |
| 5 | +import com.fasterxml.jackson.annotation.JsonCreator; |
| 6 | +import com.fasterxml.jackson.annotation.PropertyAccessor; |
| 7 | + |
| 8 | +import tools.jackson.databind.BaseMapTest; |
| 9 | +import tools.jackson.databind.ObjectMapper; |
| 10 | + |
| 11 | +/** |
| 12 | + * Test case that covers both failing-by-regression tests and passing tests. |
| 13 | + * <p>For more details, refer to |
| 14 | + * <a href="https://github.com/FasterXML/jackson-databind/issues/3906"> |
| 15 | + * [databind#3906]: Regression: 2.15.0 breaks deserialization for records when mapper.setVisibility(ALL, NONE);</a> |
| 16 | + *<p> |
| 17 | + * NOTE: fixed for 2.x in 2.16; 2 failing cases still for 3.0. |
| 18 | + */ |
| 19 | +public class RecordDeserialization3906Test extends BaseMapTest |
| 20 | +{ |
| 21 | + record Record3906(String string, int integer) { |
| 22 | + } |
| 23 | + |
| 24 | + @JsonAutoDetect(creatorVisibility = Visibility.NON_PRIVATE) |
| 25 | + record Record3906Annotated(String string, int integer) { |
| 26 | + } |
| 27 | + |
| 28 | + record Record3906Creator(String string, int integer) { |
| 29 | + @JsonCreator |
| 30 | + Record3906Creator { |
| 31 | + } |
| 32 | + } |
| 33 | + |
| 34 | + /* |
| 35 | + /********************************************************** |
| 36 | + /* Failing tests that pass in 2.14, fixed in 2.16 but not 3.x |
| 37 | + /********************************************************** |
| 38 | + */ |
| 39 | + |
| 40 | + // minimal config for reproduction |
| 41 | + public void testEmptyJsonToRecordMiminal() throws Exception { |
| 42 | + ObjectMapper mapper = jsonMapperBuilder() |
| 43 | + .changeDefaultVisibility(vc -> |
| 44 | + vc.withVisibility(PropertyAccessor.ALL, Visibility.NONE)) |
| 45 | + .build(); |
| 46 | + |
| 47 | + Record3906 recordDeser = mapper.readValue("{}", Record3906.class); |
| 48 | + |
| 49 | + assertEquals(new Record3906(null, 0), recordDeser); |
| 50 | + } |
| 51 | + |
| 52 | + // actual config used reproduction |
| 53 | + public void testEmptyJsonToRecordActualImpl() throws Exception { |
| 54 | + ObjectMapper mapper = jsonMapperBuilder() |
| 55 | + .changeDefaultVisibility(vc -> |
| 56 | + vc.withVisibility(PropertyAccessor.ALL, Visibility.NONE) |
| 57 | + .withVisibility(PropertyAccessor.FIELD, Visibility.ANY)) |
| 58 | + .build(); |
| 59 | + Record3906 recordDeser = mapper.readValue("{}", Record3906.class); |
| 60 | + |
| 61 | + assertEquals(new Record3906(null, 0), recordDeser); |
| 62 | + } |
| 63 | +} |
0 commit comments