- 
          
- 
                Notifications
    You must be signed in to change notification settings 
- Fork 1.4k
Closed
Milestone
Description
Demonstrated by the following test:
public class JacksonTest {
    @JsonIgnoreProperties(ignoreUnknown = true)
    public static class Product {
        private final String name;
        @JsonCreator(mode = PROPERTIES)
        public Product(
            @JsonProperty("name") String name
        ) {
            this.name = name;
        }
        @JsonValue
        public String getName(){
            return name;
        }
        @Override
        public String toString() {
            return "|~" + name + "~|";
        }
        @JsonCreator(mode = DELEGATING)
        public static Product from(String name){
            return new Product(name);
        }
    }
    private static final String EXAMPLE_DATA = "{\"name\":\"dummy\",\"other\":{},\"errors\":{}}";
    private static final String TEST_PRODUCT_JSON = "\"testProduct\"";
    private ObjectMapper objectMapper = new ObjectMapper();
    @Test
    public void serialization() throws Exception {
        assertEquals(TEST_PRODUCT_JSON, objectMapper.writeValueAsString(new Product("testProduct")));
    }
    @Test
    public void deserializationFromObject() throws Exception {
        assertEquals("dummy", objectMapper.readValue(EXAMPLE_DATA, Product.class).getName());
    }
    @Test
    public void deserializationFromString() throws Exception {
        assertEquals("testProduct", objectMapper.readValue(TEST_PRODUCT_JSON, Product.class).getName());
    }
}
Which is green with 2.9.1 and fails with 2.9.2:
org.junit.ComparisonFailure: 
Expected :dummy
Actual   :name
Metadata
Metadata
Assignees
Labels
No labels