|
| 1 | +package com.fasterxml.jackson.databind.tofix; |
| 2 | + |
| 3 | +import com.fasterxml.jackson.annotation.JsonMerge; |
| 4 | +import com.fasterxml.jackson.databind.ObjectMapper; |
| 5 | +import com.fasterxml.jackson.databind.json.JsonMapper; |
| 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 java.util.ArrayList; |
| 11 | +import java.util.Arrays; |
| 12 | +import java.util.Collection; |
| 13 | + |
| 14 | +import static org.assertj.core.api.Assertions.assertThat; |
| 15 | + |
| 16 | +// [databind#5281] Reading into existing instance uses creator property setup instead of accessor #5281 |
| 17 | +public class ReaderForUpdating5281Test |
| 18 | + extends DatabindTestUtil |
| 19 | +{ |
| 20 | + public static class ArrayListHolder { |
| 21 | + // Works when annotated with... |
| 22 | + // @JsonMerge |
| 23 | + Collection<String> values; |
| 24 | + |
| 25 | + public ArrayListHolder(String... values) { |
| 26 | + this.values = new ArrayList<>(); |
| 27 | + this.values.addAll(Arrays.asList(values)); |
| 28 | + } |
| 29 | + |
| 30 | + public void setValues(Collection<String> values) { |
| 31 | + this.values = values; |
| 32 | + } |
| 33 | + } |
| 34 | + |
| 35 | + @JacksonTestFailureExpected |
| 36 | + @Test |
| 37 | + public void readsIntoCreator() throws Exception { |
| 38 | + ObjectMapper mapper = JsonMapper.builder().build(); |
| 39 | + |
| 40 | + ArrayListHolder holder = mapper.readerForUpdating(new ArrayListHolder("A")) |
| 41 | + .readValue("{ \"values\" : [ \"A\", \"B\" ]}"); |
| 42 | + |
| 43 | + assertThat(holder.values).hasSize(3) |
| 44 | + .containsAll(Arrays.asList("A", "A", "B")); |
| 45 | + } |
| 46 | +} |
0 commit comments