Jackson Glossary: HandlerInstantiator

Role

This abstract class defines a way to customize details of construction of handlers by Jackson, and currently includes following types:

and more specifically, is calle in cases where Jackson must create an instance (one is NOT passed by application or other helper classes). This typically happens when handler class is defined by an annotation (like @JsonDeserializer(using=MyDeserializer.class)).

Default handling is to just locate no-argument constructor and call it via reflection, and works in many cases; but this not always enough for constructing working instances. It may be necessary to call some other constructor; or to configure instances (especially when using Dependency Injection frameworks). If so, it may make sense to extends HandlerInstantiator and register it with ObjectMapper. After doing this, all instance creations are handled by calling methods of configured instantiator.

Instantiator is allowed to return null, in which case default instantiation is used (i.e. calling no-argument constructor using Reflection)

Usage

   1     ObjectMapper mapper = new ObjectMapper();
   2     mapper.setHandlerInstantiator(new MyHandlerInstantiator());
   3     // and from here on, instances of classes defined via annotations are constructed by calling "MyHandlerInstantiator"


Back to Jackson Term Glossary


CategoryJackson

HandlerInstantiator (last edited 2011-03-21 20:34:15 by TatuSaloranta)

Copyright ©2009 FasterXML, LLC