Skip to content

rnc/jackson-annotation

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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()})
    }

About

Method hook annotation after Jackson deserialization

Resources

License

Stars

Watchers

Forks

Packages

No packages published