/jackson-annotation

Method hook annotation after Jackson deserialization

Primary LanguageGroovyApache License 2.0Apache-2.0

Build Status (Travis CI)

Jackson Post Deserialization Annotation Hook

Overview

This code provides a simple annotation that may be placed upon a method (even a private method) which will be run upon completion of the deserialization.

This has been inspired by several stackoverflow posts:

and by the following Jackson issues

Usage

In order to use this annotation the ObjectMapper instance must be correctly configured. For example:

    ObjectMapper mapper = new ObjectMapper();
    mapper.registerModule( org.goots.jackson.deserializer.JacksonPostHookDeserializer.getSimpleModule() );

Then, place the annotation upon a method to run after deserialization e.g.

    @JsonPostDeserialize
    public void postDeserialize()
    {
        myObjects.forEach( { obj -> obj.postInit()})
    }

By default the annotation will not call private methods. To force access set the parameter as follows:

    @JsonPostDeserialize(forceAccess=true)
    private void postDeserialize()
    {
        myObjects.forEach( { obj -> obj.postInit()})
    }