Class TypeDetector


  • public class TypeDetector
    extends java.lang.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 JSON instance; and an actual per-operation instance must be constructed by calling perOperationInstance(int): reason for this is that instances use simple caching to handle the common case of repeating types within JSON Arrays.

    • Field Detail

      • 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_COLLECTION

        public static final int SER_COLLECTION
        All kinds of Collections other than Lists
        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_TREE_NODE

        public static final int SER_TREE_NODE
        An implementation of TreeNode
        See Also:
        Constant Field Values
      • SER_ITERABLE

        public static final int SER_ITERABLE
        Anything that implements Iterable, but not Collection.
        See Also:
        Constant Field Values
      • CACHE_FLAGS

        protected static final int CACHE_FLAGS
      • _knownSerTypes

        protected final java.util.concurrent.ConcurrentHashMap<ClassKey,​java.lang.Integer> _knownSerTypes
        Mapping from classes to resolved type constants or indexes, to use for serialization.
      • _knownWriters

        protected final java.util.concurrent.CopyOnWriteArrayList<BeanPropertyWriter[]> _knownWriters
      • _typeResolver

        protected final TypeResolver _typeResolver
        For generic containers (Collections, Maps, arrays), we may need this guy.
      • _knownReaders

        protected final java.util.concurrent.ConcurrentHashMap<ClassKey,​ValueReader> _knownReaders
        Set of ValueReaders that we have resolved
      • _incompleteReaders

        protected java.util.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 java.lang.Object _readerLock
      • _key

        protected ClassKey _key
        Reusable lookup key; only used by per-thread instances.
      • _prevClass

        protected java.lang.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​(java.lang.Class<?> raw)
      • _findSimple

        protected int _findSimple​(java.lang.Class<?> raw,
                                  boolean forSer)
      • findSerializationType

        public final int findSerializationType​(java.lang.Class<?> raw)
        The main lookup method used to find type identifier for given raw class; including Bean types (if allowed).
      • _findPOJOSerializationType

        protected int _findPOJOSerializationType​(java.lang.Class<?> raw)
      • enumReader

        public ValueReader enumReader​(java.lang.Class<?> enumType)
      • collectionReader

        protected ValueReader collectionReader​(java.lang.Class<?> contextType,
                                               java.lang.reflect.Type collectionType)
      • collectionReader

        protected ValueReader collectionReader​(java.lang.Class<?> collectionType,
                                               ResolvedType valueType)
      • mapReader

        protected ValueReader mapReader​(java.lang.Class<?> contextType,
                                        java.lang.reflect.Type mapType)
      • findReader

        public ValueReader findReader​(java.lang.Class<?> raw)
        Method used during deserialization to find handler for given non-generic type.
      • createReader

        protected ValueReader createReader​(java.lang.Class<?> contextType,
                                           java.lang.Class<?> type,
                                           java.lang.reflect.Type genericType)
      • _resolveBeanForDeser

        protected BeanReader _resolveBeanForDeser​(java.lang.Class<?> raw)