Does Jackson have a helper method to return the @JsonProperty annotation value (i.e., the JSON property key) given a bean field name?
Context:
I’m using Jackson to convert client-supplied JSON into a Bean and then using JSR-303 to validate the bean. When validation fails, I need to report a meaningful error message back to the client. The validation objects reference the bean property; the error message should reference the JSON property. Hence the need to map from one to the other.
You can get quite a bit of information via
BeanDescriptionobject, although getting one is pretty tricky (mostly since it’s designed for Jackson’s internal use mostly).But this is used by a few Jackson extension modules, so it is supported use case. So:
you can also safely upcast it to
BasicBeanDescriptionif necessary.This gives you access to lots of information; either list of logical properties (through which you can find getter/setter/field/ctor-argument that represents it), fully resolved methods (with annotations) and such. So hopefully that is enough.
Logical properties are useful since they contain both external name (one expected from JSON) and internal name derived from getter/setter.