I am writing code that needs to access a list of class properties, as defined by Jackson's configuration.
For example, for the following class:
@JsonIgnoreProperties(value = { "intValue" }) public class MyDto { @JsonProperty("name") private String stringValue; private int intValue; private long longValue; @JsonIgnore private boolean booleanValue;
I would get [name,longValue]
, because those properties that Jackson really takes into account when serializing.
I donβt think that writing a whole piece of code to search for getters / setters and checking Jackson's annotations is the way to go because it will override Jackson.
If I can get the Jackson ObjectMapper
handle used for serialization, is there a way to get the list of properties of a Class<?>
Or Type
object? (subject to Jackson's annotations and configs)
I dug into Jackson's implementation a bit and found a POJOPropertiesCollector
, but I'm not sure how I can use it from outside Jackson (we shouldn't, I suppose).
As a last resort, I could create an instance of the class that I am checking, serialize it using ObjectMapper, and then parse JSON to find the property names, but I don't think it is clean either. will give the whole set of probes: zeros cannot be serialized, which happens in the constructor, etc.).
Any ideas?
source share