Jackson takes many factors into account when naming a field for serialization into JSON. Is it possible to use those factors in reverse in order to retrieve the value of a field in a pojo based on the name it will have once serialized?
For example, given the bean
public class Bean{
private Bean2 prop;
@JsonProperty("property")
public Bean2 getProp();
}
Is it possible to get the value of prop
given only a configured ObjectMapper
, the string "property"
and an instance of Bean
?
I know about reflection, so if I could just get "prop"
or "getProp"
I would be pretty much good to go.
@JsonProperty
. This sounds awfully roundabout, though, and there might be a better option if you explained more specifically what your use case is. – chrylis -cautiouslyoptimistic- Dec 10 '15 at 9:27@JsonProperty
to demonstrate how the field name can be an unexpected value, the annotation won't always be there. – kag0 Dec 10 '15 at 17:18