1 package com.fasterxml.jackson.annotation; 2 3 import com.fasterxml.jackson.annotation.ObjectIdGenerator.IdKey; 4 5 /** 6 * Definition of API used for resolving actual Java object from 7 * Object Identifiers (as annotated using {@link JsonIdentityInfo}). 8 * 9 * @since 2.4 10 */ 11 public interface ObjectIdResolver { 12 /** 13 * Method called when a POJO is deserialized and has an Object Identifier. 14 * Method exists so that implementation can keep track of existing object in 15 * JSON stream that could be useful for further resolution. 16 * 17 * @param id The Object Identifer 18 * @param pojo The POJO associated to that Identifier 19 */ bindItem(IdKey id, Object pojo)20 void bindItem(IdKey id, Object pojo); 21 22 /** 23 * Method called when deserialization encounters the given Object Identifier 24 * and requires the POJO associated with it. 25 * 26 * @param id The Object Identifier 27 * @return The POJO, or null if unable to resolve. 28 */ resolveId(IdKey id)29 Object resolveId(IdKey id); 30 31 /** 32 * Factory method called to create a new instance to use for 33 * deserialization: needed since resolvers may have state (a pool of 34 * objects). 35 * <p> 36 * Note that actual type of 'context' is 37 * <code>com.fasterxml.jackson.databind.DeserializationContext</code>, but 38 * can not be declared here as type itself (as well as call to this object) 39 * comes from databind package. 40 * 41 * @param context 42 * Deserialization context object used (of type 43 * <code>com.fasterxml.jackson.databind.DeserializationContext</code> 44 * ; may be needed by more complex resolvers to access contextual 45 * information such as configuration. 46 */ newForDeserialization(Object context)47 ObjectIdResolver newForDeserialization(Object context); 48 49 /** 50 * Method called to check whether this resolver instance can be used for 51 * Object Ids of specific resolver type; determination is based by passing a 52 * configured "blueprint" (prototype) instance; from which the actual 53 * instances are created (using {@link #newForDeserialization}). 54 * 55 * @return True if this instance can be used as-is; false if not 56 */ canUseFor(ObjectIdResolver resolverType)57 boolean canUseFor(ObjectIdResolver resolverType); 58 } 59