Package com.fasterxml.jackson.jr.ob.impl
Class TypeDetector
- java.lang.Object
-
- com.fasterxml.jackson.jr.ob.impl.TypeDetector
-
public class TypeDetector extends Object
Helper object used for efficient detection of type information relevant to our conversion needs when writing out Java Objects as JSON.Note that usage pattern is such that a single "root" instance is kept by each
JSONinstance; and an actual per-operation instance must be constructed by callingperOperationInstance(int): reason for this is that instances use simple caching to handle the common case of repeating types within JSON Arrays.
-
-
Field Summary
Fields Modifier and Type Field Description protected int_featuresprotected Map<ClassKey,ValueReader>_incompleteReadersDuring resolution, some readers may be in-progress, but need to be linked: for example, with cyclic type references.protected ClassKey_keyReusable lookup key; only used by per-thread instances.protected ConcurrentHashMap<ClassKey,ValueReader>_knownReadersSet ofValueReaders that we have resolvedprotected ConcurrentHashMap<ClassKey,Integer>_knownSerTypesMapping from classes to resolved type constants or indexes, to use for serialization.protected CopyOnWriteArrayList<BeanPropertyWriter[]>_knownWritersprotected Class<?>_prevClassprotected int_prevTypeprotected Object_readerLockprotected TypeResolver_typeResolverFor generic containers (Collections, Maps, arrays), we may need this guy.protected static intCACHE_FLAGSprotected static intMAX_CACHED_READERSWhile we should be able to cache all types in the active working set, we should also avoid potential unbounded retention, since there is generally just one big `TypeDetector` instances per JVM (or at least ClassLoader).protected BeanPropertyWriter[]NO_PROPS_FOR_WRITEstatic intSER_BOOLEANstatic intSER_BOOLEAN_ARRAYstatic intSER_BYTE_ARRAYstatic intSER_CALENDARstatic intSER_CHARstatic intSER_CHAR_ARRAYstatic intSER_CHARACTER_SEQUENCEstatic intSER_CLASSstatic intSER_COLLECTIONAll kinds ofCollections other thanListsstatic intSER_DATEstatic intSER_ENUMstatic intSER_FILEstatic intSER_INT_ARRAYstatic intSER_ITERABLEAnything that implementsIterable, but notCollection.static intSER_LISTAll kinds ofLists.static intSER_LONG_ARRAYstatic intSER_MAPAll kinds ofMaps.static intSER_NUMBER_BIG_DECIMALstatic intSER_NUMBER_BIG_INTEGERstatic intSER_NUMBER_BYTEstatic intSER_NUMBER_DOUBLEstatic intSER_NUMBER_FLOATstatic intSER_NUMBER_INTEGERstatic intSER_NUMBER_LONGstatic intSER_NUMBER_SHORTstatic intSER_OBJECT_ARRAYArrays of non-primitive typesstatic intSER_STRINGstatic intSER_TREE_NODEAn implementation ofTreeNodestatic intSER_UNKNOWNType not yet resolvedstatic intSER_URIstatic intSER_URLstatic intSER_UUID
-
Constructor Summary
Constructors Modifier Constructor Description protectedTypeDetector(int features)Constructor for the blueprint instanceprotectedTypeDetector(TypeDetector base, int features)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected int_findPOJOSerializationType(Class<?> raw)protected int_findSimple(Class<?> raw, boolean forSer)protected BeanReader_resolveBeanForDeser(Class<?> raw)static TypeDetectorblueprint(int features)protected ValueReadercollectionReader(Class<?> collectionType, ResolvedType valueType)protected ValueReadercollectionReader(Class<?> contextType, Type collectionType)protected ValueReadercreateReader(Class<?> contextType, Class<?> type, Type genericType)ValueReaderenumReader(Class<?> enumType)ValueReaderfindReader(Class<?> raw)Method used during deserialization to find handler for given non-generic type.intfindSerializationType(Class<?> raw)The main lookup method used to find type identifier for given raw class; including Bean types (if allowed).BeanPropertyWriter[]getPropertyWriters(int index)protected ValueReadermapReader(Class<?> mapType, ResolvedType valueType)protected ValueReadermapReader(Class<?> contextType, Type mapType)TypeDetectorperOperationInstance(int features)protected BeanPropertyWriter[]resolveBeanForSer(Class<?> raw, POJODefinition classDef)protected POJODefinitionresolvePOJODefinition(Class<?> raw)
-
-
-
Field Detail
-
NO_PROPS_FOR_WRITE
protected final BeanPropertyWriter[] NO_PROPS_FOR_WRITE
-
MAX_CACHED_READERS
protected static final int MAX_CACHED_READERS
While we should be able to cache all types in the active working set, we should also avoid potential unbounded retention, since there is generally just one big `TypeDetector` instances per JVM (or at least ClassLoader).- See Also:
- Constant Field Values
-
SER_UNKNOWN
public static final int SER_UNKNOWN
Type not yet resolved- See Also:
- Constant Field Values
-
SER_MAP
public static final int SER_MAP
All kinds ofMaps.- See Also:
- Constant Field Values
-
SER_LIST
public static final int SER_LIST
All kinds ofLists.- See Also:
- Constant Field Values
-
SER_COLLECTION
public static final int SER_COLLECTION
All kinds ofCollections other thanLists- See Also:
- Constant Field Values
-
SER_OBJECT_ARRAY
public static final int SER_OBJECT_ARRAY
Arrays of non-primitive types- See Also:
- Constant Field Values
-
SER_INT_ARRAY
public static final int SER_INT_ARRAY
- See Also:
- Constant Field Values
-
SER_LONG_ARRAY
public static final int SER_LONG_ARRAY
- See Also:
- Constant Field Values
-
SER_BOOLEAN_ARRAY
public static final int SER_BOOLEAN_ARRAY
- See Also:
- Constant Field Values
-
SER_TREE_NODE
public static final int SER_TREE_NODE
An implementation ofTreeNode- See Also:
- Constant Field Values
-
SER_STRING
public static final int SER_STRING
- See Also:
- Constant Field Values
-
SER_CHARACTER_SEQUENCE
public static final int SER_CHARACTER_SEQUENCE
- See Also:
- Constant Field Values
-
SER_CHAR_ARRAY
public static final int SER_CHAR_ARRAY
- See Also:
- Constant Field Values
-
SER_BYTE_ARRAY
public static final int SER_BYTE_ARRAY
- See Also:
- Constant Field Values
-
SER_NUMBER_BYTE
public static final int SER_NUMBER_BYTE
- See Also:
- Constant Field Values
-
SER_NUMBER_SHORT
public static final int SER_NUMBER_SHORT
- See Also:
- Constant Field Values
-
SER_NUMBER_INTEGER
public static final int SER_NUMBER_INTEGER
- See Also:
- Constant Field Values
-
SER_NUMBER_LONG
public static final int SER_NUMBER_LONG
- See Also:
- Constant Field Values
-
SER_NUMBER_FLOAT
public static final int SER_NUMBER_FLOAT
- See Also:
- Constant Field Values
-
SER_NUMBER_DOUBLE
public static final int SER_NUMBER_DOUBLE
- See Also:
- Constant Field Values
-
SER_NUMBER_BIG_INTEGER
public static final int SER_NUMBER_BIG_INTEGER
- See Also:
- Constant Field Values
-
SER_NUMBER_BIG_DECIMAL
public static final int SER_NUMBER_BIG_DECIMAL
- See Also:
- Constant Field Values
-
SER_BOOLEAN
public static final int SER_BOOLEAN
- See Also:
- Constant Field Values
-
SER_CHAR
public static final int SER_CHAR
- See Also:
- Constant Field Values
-
SER_ENUM
public static final int SER_ENUM
- See Also:
- Constant Field Values
-
SER_DATE
public static final int SER_DATE
- See Also:
- Constant Field Values
-
SER_CALENDAR
public static final int SER_CALENDAR
- See Also:
- Constant Field Values
-
SER_CLASS
public static final int SER_CLASS
- See Also:
- Constant Field Values
-
SER_FILE
public static final int SER_FILE
- See Also:
- Constant Field Values
-
SER_UUID
public static final int SER_UUID
- See Also:
- Constant Field Values
-
SER_URL
public static final int SER_URL
- See Also:
- Constant Field Values
-
SER_URI
public static final int SER_URI
- See Also:
- Constant Field Values
-
SER_ITERABLE
public static final int SER_ITERABLE
Anything that implementsIterable, but notCollection.- See Also:
- Constant Field Values
-
CACHE_FLAGS
protected static final int CACHE_FLAGS
-
_knownSerTypes
protected final ConcurrentHashMap<ClassKey,Integer> _knownSerTypes
Mapping from classes to resolved type constants or indexes, to use for serialization.
-
_knownWriters
protected final CopyOnWriteArrayList<BeanPropertyWriter[]> _knownWriters
-
_typeResolver
protected final TypeResolver _typeResolver
For generic containers (Collections, Maps, arrays), we may need this guy.
-
_knownReaders
protected final ConcurrentHashMap<ClassKey,ValueReader> _knownReaders
Set ofValueReaders that we have resolved
-
_incompleteReaders
protected Map<ClassKey,ValueReader> _incompleteReaders
During resolution, some readers may be in-progress, but need to be linked: for example, with cyclic type references.
-
_readerLock
protected final Object _readerLock
-
_key
protected ClassKey _key
Reusable lookup key; only used by per-thread instances.
-
_prevClass
protected Class<?> _prevClass
-
_prevType
protected int _prevType
-
_features
protected int _features
-
-
Constructor Detail
-
TypeDetector
protected TypeDetector(int features)
Constructor for the blueprint instance
-
TypeDetector
protected TypeDetector(TypeDetector base, int features)
-
-
Method Detail
-
blueprint
public static final TypeDetector blueprint(int features)
-
perOperationInstance
public TypeDetector perOperationInstance(int features)
-
resolvePOJODefinition
protected POJODefinition resolvePOJODefinition(Class<?> raw)
-
_findSimple
protected int _findSimple(Class<?> raw, boolean forSer)
-
getPropertyWriters
public BeanPropertyWriter[] getPropertyWriters(int index)
-
findSerializationType
public final int findSerializationType(Class<?> raw)
The main lookup method used to find type identifier for given raw class; including Bean types (if allowed).
-
_findPOJOSerializationType
protected int _findPOJOSerializationType(Class<?> raw)
-
resolveBeanForSer
protected BeanPropertyWriter[] resolveBeanForSer(Class<?> raw, POJODefinition classDef)
-
enumReader
public ValueReader enumReader(Class<?> enumType)
-
collectionReader
protected ValueReader collectionReader(Class<?> contextType, Type collectionType)
-
collectionReader
protected ValueReader collectionReader(Class<?> collectionType, ResolvedType valueType)
-
mapReader
protected ValueReader mapReader(Class<?> contextType, Type mapType)
-
mapReader
protected ValueReader mapReader(Class<?> mapType, ResolvedType valueType)
-
findReader
public ValueReader findReader(Class<?> raw)
Method used during deserialization to find handler for given non-generic type.
-
createReader
protected ValueReader createReader(Class<?> contextType, Class<?> type, Type genericType)
-
_resolveBeanForDeser
protected BeanReader _resolveBeanForDeser(Class<?> raw)
-
-