Implement POJO serializer "decorator" abstraction to allow for augmenting POJO Serializations
See original GitHub issue(note: also consider possibly allowing decorators for Collection
/array types, scalars)
One recurring feature request is that of ability to add more “virtual” properties to serialize. Although it is relatively easy to modify behavior of existing properties (or anything that can be accessed via existing fields and/or methods), it is surprisingly difficult to add anything that “isn’t there”.
But it would be quite easy to allow addition of handlers called before and after serializing properties of POJOs (pre/post hooks); right after START_OBJECT and before END_OBJECT.
I think what is needed is:
- New handler type that contains methods to call
- Addition of a new property in
@JsonSerialize
to define handler to use
Another possible improvement (which could be deferred for future) would be to allow registering such handler externally. One challenge there is the question of how to match handler to type(s); as well as if and how to chain these. Chaining would make sense to prevent modules from accidentally overriding/removing handlers; but might cause issues of its own.
Issue Analytics
- State:
- Created 10 years ago
- Comments:22 (11 by maintainers)
Top GitHub Comments
Adding a comment for people who end up here via http://jira.codehaus.org/browse/JACKSON-645 or http://jira.codehaus.org/browse/JACKSON-538 and are looking for a method which is called after a deserializer completes. I was able to achieve the desired effect by including an annotation and writing a converter which uses the same class as input and output.
For those looking for a way to add functionality before and after deserialization, this worked perfectly for my needs:
http://stackoverflow.com/questions/18313323/how-do-i-call-the-default-deserializer-from-a-custom-deserializer-in-jackson/18405958#18405958