1 package com.fasterxml.jackson.databind.deser; 2 3 import com.fasterxml.jackson.databind.*; 4 5 /** 6 * Add-on interface that {@link JsonDeserializer}s can implement to get a callback 7 * that can be used to create contextual (context-dependent) instances of 8 * deserializer to use for handling properties of supported type. 9 * This can be useful 10 * for deserializers that can be configured by annotations, or should otherwise 11 * have differing behavior depending on what kind of property is being deserialized. 12 *<p> 13 * Note that in cases where deserializer needs both contextualization and 14 * resolution -- that is, implements both this interface and {@link ResolvableDeserializer} 15 * -- resolution via {@link ResolvableDeserializer} occurs first, and contextual 16 * resolution (via this interface) later on. 17 */ 18 public interface ContextualDeserializer 19 { 20 /** 21 * Method called to see if a different (or differently configured) deserializer 22 * is needed to deserialize values of specified property. 23 * Note that instance that this method is called on is typically shared one and 24 * as a result method should <b>NOT</b> modify this instance but rather construct 25 * and return a new instance. This instance should only be returned as-is, in case 26 * it is already suitable for use. 27 * 28 * @param ctxt Deserialization context to access configuration, additional 29 * deserializers that may be needed by this deserializer 30 * @param property Method, field or constructor parameter that represents the property 31 * (and is used to assign deserialized value). 32 * Should be available; but there may be cases where caller cannot provide it and 33 * null is passed instead (in which case impls usually pass 'this' deserializer as is) 34 * 35 * @return Deserializer to use for deserializing values of specified property; 36 * may be this instance or a new instance. 37 * 38 * @throws JsonMappingException 39 */ createContextual(DeserializationContext ctxt, BeanProperty property)40 public JsonDeserializer<?> createContextual(DeserializationContext ctxt, 41 BeanProperty property) 42 throws JsonMappingException; 43 } 44