Closed
Description
This following example works as expected
public class JacksonForUpdate {
public static class Bean {
private String name;
private Map<String, Object> properties;
public void setName(String name) {
this.name = name;
}
@JsonCreator
public Bean(JsonNode node, @JacksonInject ObjectMapper mapper) throws IOException {
this.properties = mapper.convertValue(node, Map.class);
mapper.readerForUpdating(this).readValue(node);
}
@Override
public String toString() {
return "Bean{" +
"name='" + name + '\'' +
", properties=" + properties +
'}';
}
}
public static void main(String[] args) throws IOException {
ObjectMapper mapper = new ObjectMapper();
// make the mapper to be available for the bean
mapper.setInjectableValues(new InjectableValues.Std().addValue(ObjectMapper.class, mapper));
final ObjectNode objectNode = mapper.createObjectNode();
objectNode.put("name", "value");
System.out.println(
mapper.treeToValue(
objectNode, Bean.class));
}
}
The next example fails with an exception: Conflicting setter definitions for property "config":
com.fasterxml.jackson.databind.ObjectMapper#setConfig(1 params) vs com.fasterxml.jackson.databind.ObjectMapper#setConfig(1 params)
public class JacksonForUpdate {
public static class Bean {
private String name;
@JsonCreator
public Bean(@JsonProperty("name") String name, @JacksonInject ObjectMapper mapper) throws IOException {
this.name = name;
}
@Override
public String toString() {
return "Bean{" +
"name='" + name + '\'' +
'}';
}
}
public static void main(String[] args) throws IOException {
ObjectMapper mapper = new ObjectMapper();
// make the mapper to be available for the bean
mapper.setInjectableValues(new InjectableValues.Std().addValue(ObjectMapper.class, mapper));
final ObjectNode objectNode = mapper.createObjectNode();
objectNode.put("name", "value");
System.out.println(
mapper.treeToValue(
objectNode, Bean.class));
}
}
Metadata
Metadata
Assignees
Labels
No labels