Hasaki :
@Data
public class Tests {
@JsonProperty("comment")
private String notes;
}
I know how to use @JsonProperty to rename field as another name, but when does it rename the object field? For example, notes
is renamed to comment
.
I try to read the source code and find that there is some relative code in com.fasterxml.jackson.databind.ser.std.BeanSerializerBase#serializeFields
and com.fasterxml.jackson.databind.ser.BeanPropertyWriter#serializeAsField
. But the field has already been renamed as comment
. So where does @JsonProperty
rename object field?
i.bondarenko :
Property name resolving happens in com.fasterxml.jackson.databind.introspect.JacksonAnnotationIntrospector
Have a look at this fragment:
public PropertyName findNameForDeserialization(Annotated a) {
...
// Get JsonProperty value for the field
JsonProperty pann = (JsonProperty)this._findAnnotation(a, JsonProperty.class);
if (pann != null) {
// here we are !!!
return PropertyName.construct(pann.value());
} else {
return !useDefault && !this._hasOneOf(a, ANNOTATIONS_TO_INFER_DESER) ? null : PropertyName.USE_DEFAULT;
}
}
All it happens in POJOPropertiesCollector.collectAll()
Guess you like
Origin http://43.154.161.224:23101/article/api/json?id=324780&siteId=1