Ideally, it would look like this:
List<String> props = objectMapper.getKnownProperties(MyPojo.class);
Alas, there is no such method. The approach that usually works is to explicitly set Include.ALWAYS as the default ObjectMapper, instantly instantiate the class, convert it to a map, and examine the key set. However, classes can still override ObjectMapper, including the behavior given by the annotation.
Is there a more elegant approach? At least is there a way to override class annotations using the mapper object?
Edit:
To clarify, these pojos / javabeans / DTO are intended for use with Jackson and are already compiled with annotations to lead to a certain serialization. It just so happens that I need to dynamically know how I can be at the forefront, ideally, without duplicating the information already available to Jackson. However, if another framework offers this functionality, I would be interested to know. :)
source share