Package org.codehaus.jackson.map.deser
Class StdDeserializerProvider
- java.lang.Object
-
- org.codehaus.jackson.map.DeserializerProvider
-
- org.codehaus.jackson.map.deser.StdDeserializerProvider
-
public class StdDeserializerProvider extends DeserializerProvider
DefaultDeserializerProvider
implementation. Handles low-level caching (non-root) aspects of deserializer handling; all construction details are delegated to configuredDeserializerFactory
instance that the provider owns.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static class
StdDeserializerProvider.WrappedDeserializer
Simple deserializer that will call configured type deserializer, passing in configured data deserializer, and exposing it all as a simple deserializer.
-
Field Summary
Fields Modifier and Type Field Description protected java.util.concurrent.ConcurrentHashMap<JavaType,JsonDeserializer<java.lang.Object>>
_cachedDeserializers
We will also cache some dynamically constructed deserializers; specifically, ones that are expensive to construct.protected DeserializerFactory
_factory
Factory responsible for constructing actual deserializers, if not one of pre-configured types.protected java.util.HashMap<JavaType,JsonDeserializer<java.lang.Object>>
_incompleteDeserializers
During deserializer construction process we may need to keep track of partially completed deserializers, to resolve cyclic dependencies.protected RootNameLookup
_rootNames
-
Constructor Summary
Constructors Constructor Description StdDeserializerProvider()
Default constructor.StdDeserializerProvider(DeserializerFactory f)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected JsonDeserializer<java.lang.Object>
_createAndCache2(DeserializationConfig config, JavaType type, BeanProperty property)
Method that handles actual construction (via factory) and caching (both intermediate and eventual)protected JsonDeserializer<java.lang.Object>
_createAndCacheValueDeserializer(DeserializationConfig config, JavaType type, BeanProperty property)
Method that will try to create a deserializer for given type, and resolve and cache it if necessaryprotected JsonDeserializer<java.lang.Object>
_createDeserializer(DeserializationConfig config, JavaType type, BeanProperty property)
protected JsonDeserializer<java.lang.Object>
_findCachedDeserializer(JavaType type)
protected KeyDeserializer
_handleUnknownKeyDeserializer(JavaType type)
protected JsonDeserializer<java.lang.Object>
_handleUnknownValueDeserializer(JavaType type)
protected void
_resolveDeserializer(DeserializationConfig config, ResolvableDeserializer ser)
int
cachedDeserializersCount()
Method that can be used to determine how many deserializers this provider is caching currently (if it does caching: default implementation does) Exact count depends on what kind of deserializers get cached; default implementation caches only dynamically constructed deserializers, but not eagerly constructed standard deserializers (which is different from how serializer provider works).SerializedString
findExpectedRootName(DeserializationConfig config, JavaType type)
Method that can be used to try find expected root name for given typeKeyDeserializer
findKeyDeserializer(DeserializationConfig config, JavaType type, BeanProperty property)
Method called to get hold of a deserializer to use for deserializing keys forMap
.JsonDeserializer<java.lang.Object>
findTypedValueDeserializer(DeserializationConfig config, JavaType type, BeanProperty property)
Method called to locate deserializer for given type, as well as matching type deserializer (if one is needed); and if type deserializer is needed, construct a "wrapped" deserializer that can extract and use type information for calling actual deserializer.JsonDeserializer<java.lang.Object>
findValueDeserializer(DeserializationConfig config, JavaType propertyType, BeanProperty property)
Method called to get hold of a deserializer for a value of given type; or if no such deserializer can be found, a default handler (which may do a best-effort generic serialization or just simply throw an exception when invoked).void
flushCachedDeserializers()
Method that will drop all dynamically constructed deserializers (ones that are counted as result value forcachedDeserializersCount()
).boolean
hasValueDeserializerFor(DeserializationConfig config, JavaType type)
Method that can be called to find out whether a deserializer can be found for given typeJavaType
mapAbstractType(DeserializationConfig config, JavaType type)
Method that can be called to try to resolve an abstract type (interface, abstract class) into a concrete type, or at least something "more concrete" (abstract class instead of interface).DeserializerProvider
withAbstractTypeResolver(AbstractTypeResolver resolver)
DeserializerProvider
withAdditionalDeserializers(Deserializers d)
Method that is to configureDeserializerFactory
that provider has to use specified deserializer provider, with highest precedence (that is, additional providers have higher precedence than default one or previously added ones)DeserializerProvider
withAdditionalKeyDeserializers(KeyDeserializers d)
DeserializerProvider
withDeserializerModifier(BeanDeserializerModifier modifier)
StdDeserializerProvider
withFactory(DeserializerFactory factory)
Method that sub-classes need to override, to ensure that fluent-factory methods will produce proper sub-type.DeserializerProvider
withValueInstantiators(ValueInstantiators instantiators)
Method that will construct a new instance with specified additional value instantiators (i.e.
-
-
-
Field Detail
-
_cachedDeserializers
protected final java.util.concurrent.ConcurrentHashMap<JavaType,JsonDeserializer<java.lang.Object>> _cachedDeserializers
We will also cache some dynamically constructed deserializers; specifically, ones that are expensive to construct. This currently means bean and Enum deserializers; array, List and Map deserializers will not be cached.Given that we don't expect much concurrency for additions (should very quickly converge to zero after startup), let's explicitly define a low concurrency setting.
-
_incompleteDeserializers
protected final java.util.HashMap<JavaType,JsonDeserializer<java.lang.Object>> _incompleteDeserializers
During deserializer construction process we may need to keep track of partially completed deserializers, to resolve cyclic dependencies. This is the map used for storing deserializers before they are fully complete.
-
_rootNames
protected final RootNameLookup _rootNames
-
_factory
protected DeserializerFactory _factory
Factory responsible for constructing actual deserializers, if not one of pre-configured types.
-
-
Constructor Detail
-
StdDeserializerProvider
public StdDeserializerProvider()
Default constructor. Equivalent to callingnew StdDeserializerProvider(BeanDeserializerFactory.instance);
-
StdDeserializerProvider
public StdDeserializerProvider(DeserializerFactory f)
-
-
Method Detail
-
withAdditionalDeserializers
public DeserializerProvider withAdditionalDeserializers(Deserializers d)
Description copied from class:DeserializerProvider
Method that is to configureDeserializerFactory
that provider has to use specified deserializer provider, with highest precedence (that is, additional providers have higher precedence than default one or previously added ones)- Specified by:
withAdditionalDeserializers
in classDeserializerProvider
-
withAdditionalKeyDeserializers
public DeserializerProvider withAdditionalKeyDeserializers(KeyDeserializers d)
- Specified by:
withAdditionalKeyDeserializers
in classDeserializerProvider
-
withDeserializerModifier
public DeserializerProvider withDeserializerModifier(BeanDeserializerModifier modifier)
- Specified by:
withDeserializerModifier
in classDeserializerProvider
-
withAbstractTypeResolver
public DeserializerProvider withAbstractTypeResolver(AbstractTypeResolver resolver)
- Specified by:
withAbstractTypeResolver
in classDeserializerProvider
-
withValueInstantiators
public DeserializerProvider withValueInstantiators(ValueInstantiators instantiators)
Description copied from class:DeserializerProvider
Method that will construct a new instance with specified additional value instantiators (i.e. does NOT replace existing ones)- Specified by:
withValueInstantiators
in classDeserializerProvider
-
withFactory
public StdDeserializerProvider withFactory(DeserializerFactory factory)
Description copied from class:DeserializerProvider
Method that sub-classes need to override, to ensure that fluent-factory methods will produce proper sub-type.- Specified by:
withFactory
in classDeserializerProvider
-
mapAbstractType
public JavaType mapAbstractType(DeserializationConfig config, JavaType type) throws JsonMappingException
Description copied from class:DeserializerProvider
Method that can be called to try to resolve an abstract type (interface, abstract class) into a concrete type, or at least something "more concrete" (abstract class instead of interface). Will either return passed type, or a more specific type.- Specified by:
mapAbstractType
in classDeserializerProvider
- Throws:
JsonMappingException
-
findExpectedRootName
public SerializedString findExpectedRootName(DeserializationConfig config, JavaType type) throws JsonMappingException
Description copied from class:DeserializerProvider
Method that can be used to try find expected root name for given type- Specified by:
findExpectedRootName
in classDeserializerProvider
- Throws:
JsonMappingException
-
findValueDeserializer
public JsonDeserializer<java.lang.Object> findValueDeserializer(DeserializationConfig config, JavaType propertyType, BeanProperty property) throws JsonMappingException
Description copied from class:DeserializerProvider
Method called to get hold of a deserializer for a value of given type; or if no such deserializer can be found, a default handler (which may do a best-effort generic serialization or just simply throw an exception when invoked).Note: this method is only called for value types; not for keys. Key deserializers can be accessed using
DeserializerProvider.findKeyDeserializer(org.codehaus.jackson.map.DeserializationConfig, org.codehaus.jackson.type.JavaType, org.codehaus.jackson.map.BeanProperty)
.- Specified by:
findValueDeserializer
in classDeserializerProvider
- Parameters:
config
- Deserialization configurationpropertyType
- Declared type of the value to deserializer (obtained using 'setter' method signature and/or type annotationsproperty
- Object that represents accessor for property value; field, setter method or constructor parameter.- Throws:
JsonMappingException
- if there are fatal problems with accessing suitable deserializer; including that of not finding any serializer
-
findTypedValueDeserializer
public JsonDeserializer<java.lang.Object> findTypedValueDeserializer(DeserializationConfig config, JavaType type, BeanProperty property) throws JsonMappingException
Description copied from class:DeserializerProvider
Method called to locate deserializer for given type, as well as matching type deserializer (if one is needed); and if type deserializer is needed, construct a "wrapped" deserializer that can extract and use type information for calling actual deserializer.Since this method is only called for root elements, no referral information is taken.
- Specified by:
findTypedValueDeserializer
in classDeserializerProvider
- Throws:
JsonMappingException
-
findKeyDeserializer
public KeyDeserializer findKeyDeserializer(DeserializationConfig config, JavaType type, BeanProperty property) throws JsonMappingException
Description copied from class:DeserializerProvider
Method called to get hold of a deserializer to use for deserializing keys forMap
.- Specified by:
findKeyDeserializer
in classDeserializerProvider
- Throws:
JsonMappingException
- if there are fatal problems with accessing suitable key deserializer; including that of not finding any serializer
-
hasValueDeserializerFor
public boolean hasValueDeserializerFor(DeserializationConfig config, JavaType type)
Method that can be called to find out whether a deserializer can be found for given type- Specified by:
hasValueDeserializerFor
in classDeserializerProvider
-
cachedDeserializersCount
public int cachedDeserializersCount()
Description copied from class:DeserializerProvider
Method that can be used to determine how many deserializers this provider is caching currently (if it does caching: default implementation does) Exact count depends on what kind of deserializers get cached; default implementation caches only dynamically constructed deserializers, but not eagerly constructed standard deserializers (which is different from how serializer provider works).The main use case for this method is to allow conditional flushing of deserializer cache, if certain number of entries is reached.
- Specified by:
cachedDeserializersCount
in classDeserializerProvider
-
flushCachedDeserializers
public void flushCachedDeserializers()
Method that will drop all dynamically constructed deserializers (ones that are counted as result value forcachedDeserializersCount()
). This can be used to remove memory usage (in case some deserializers are only used once or so), or to force re-construction of deserializers after configuration changes for mapper than owns the provider.- Specified by:
flushCachedDeserializers
in classDeserializerProvider
- Since:
- 1.4
-
_findCachedDeserializer
protected JsonDeserializer<java.lang.Object> _findCachedDeserializer(JavaType type)
-
_createAndCacheValueDeserializer
protected JsonDeserializer<java.lang.Object> _createAndCacheValueDeserializer(DeserializationConfig config, JavaType type, BeanProperty property) throws JsonMappingException
Method that will try to create a deserializer for given type, and resolve and cache it if necessary- Parameters:
config
- Configurationtype
- Type of property to deserializerproperty
- Property (field, setter, ctor arg) to use deserializer for- Throws:
JsonMappingException
-
_createAndCache2
protected JsonDeserializer<java.lang.Object> _createAndCache2(DeserializationConfig config, JavaType type, BeanProperty property) throws JsonMappingException
Method that handles actual construction (via factory) and caching (both intermediate and eventual)- Throws:
JsonMappingException
-
_createDeserializer
protected JsonDeserializer<java.lang.Object> _createDeserializer(DeserializationConfig config, JavaType type, BeanProperty property) throws JsonMappingException
- Throws:
JsonMappingException
-
_resolveDeserializer
protected void _resolveDeserializer(DeserializationConfig config, ResolvableDeserializer ser) throws JsonMappingException
- Throws:
JsonMappingException
-
_handleUnknownValueDeserializer
protected JsonDeserializer<java.lang.Object> _handleUnknownValueDeserializer(JavaType type) throws JsonMappingException
- Throws:
JsonMappingException
-
_handleUnknownKeyDeserializer
protected KeyDeserializer _handleUnknownKeyDeserializer(JavaType type) throws JsonMappingException
- Throws:
JsonMappingException
-
-