Class JSONReader


  • public class JSONReader
    extends ValueReader
    Object that handles construction of simple Objects from JSON.

    Life-cycle is such that initial instance (called blueprint) is constructed first (including possible configuration using mutant factory methods). This blueprint object acts as a factory, and is never used for direct writing; instead, per-call instance is created by calling perOperationInstance(int, com.fasterxml.jackson.core.JsonParser).

    • Constructor Summary

      Constructors 
      Modifier Constructor Description
        JSONReader​(int features, TypeDetector td, com.fasterxml.jackson.core.TreeCodec treeCodec, CollectionBuilder lb, MapBuilder mb)
      Constructor used for creating the blueprint instances.
      protected JSONReader​(JSONReader base, int features, TypeDetector td, com.fasterxml.jackson.core.JsonParser p)
      Constructor used for per-operation (non-blueprint) instance.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected CollectionBuilder _collectionBuilder​(java.lang.Class<?> collType)  
      protected MapBuilder _mapBuilder​(java.lang.Class<?> mapType)  
      protected com.fasterxml.jackson.core.TreeCodec _treeCodec()  
      protected JSONReader _with​(int features, TypeDetector td, com.fasterxml.jackson.core.TreeCodec tc, CollectionBuilder lb, MapBuilder mb)
      Overridable method that all mutant factories call if a new instance is to be constructed
      boolean arraysAsLists()  
      JSONReader perOperationInstance​(int features, com.fasterxml.jackson.core.JsonParser p)  
      java.lang.Object read​(JSONReader reader, com.fasterxml.jackson.core.JsonParser p)  
      java.lang.Object[] readArray()
      Method for reading a JSON Array from input and building a Object[] out of it.
      <T> T[] readArrayOf​(java.lang.Class<T> type)  
      <T> T readBean​(java.lang.Class<T> type)
      Method for reading a JSON Object from input and building a Bean of specified type out of it; Bean has to conform to standard Java Bean specification by having setters for passing JSON Object properties.
      java.util.List<java.lang.Object> readList()
      Method for reading a JSON Array from input and building a List out of it.
      <T> java.util.List<T> readListOf​(java.lang.Class<T> type)
      Method for reading a JSON Array from input and building a List out of it.
      java.util.Map<java.lang.Object,​java.lang.Object> readMap()
      Method for reading a JSON Object from input and building a Map out of it.
      java.lang.Object readNext​(JSONReader reader, com.fasterxml.jackson.core.JsonParser p)  
      java.lang.Object readValue()
      Method for reading a "simple" Object of type indicated by JSON content: Map for JSON Object, Map for JSON Array (or, Object[] if so configured), String for JSON String value and so on.
      JSONReader with​(CollectionBuilder lb)  
      JSONReader with​(MapBuilder mb)  
      JSONReader withFeatures​(int features)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • _features

        protected final int _features
      • _treeCodec

        protected final com.fasterxml.jackson.core.TreeCodec _treeCodec
      • _typeDetector

        protected final TypeDetector _typeDetector
        Object that is used to resolve types of values dynamically.
      • _mapBuilder

        protected final MapBuilder _mapBuilder
        Handler that takes care of constructing Maps as needed
      • _collectionBuilder

        protected final CollectionBuilder _collectionBuilder
        Handler that takes care of constructing Maps as needed
      • _parser

        protected final com.fasterxml.jackson.core.JsonParser _parser
    • Constructor Detail

      • JSONReader

        public JSONReader​(int features,
                          TypeDetector td,
                          com.fasterxml.jackson.core.TreeCodec treeCodec,
                          CollectionBuilder lb,
                          MapBuilder mb)
        Constructor used for creating the blueprint instances.
      • JSONReader

        protected JSONReader​(JSONReader base,
                             int features,
                             TypeDetector td,
                             com.fasterxml.jackson.core.JsonParser p)
        Constructor used for per-operation (non-blueprint) instance.
    • Method Detail

      • read

        public java.lang.Object read​(JSONReader reader,
                                     com.fasterxml.jackson.core.JsonParser p)
                              throws java.io.IOException
        Specified by:
        read in class ValueReader
        Throws:
        java.io.IOException
      • readNext

        public java.lang.Object readNext​(JSONReader reader,
                                         com.fasterxml.jackson.core.JsonParser p)
                                  throws java.io.IOException
        Specified by:
        readNext in class ValueReader
        Throws:
        java.io.IOException
      • withFeatures

        public JSONReader withFeatures​(int features)
      • perOperationInstance

        public JSONReader perOperationInstance​(int features,
                                               com.fasterxml.jackson.core.JsonParser p)
      • arraysAsLists

        public boolean arraysAsLists()
        Since:
        2.8
      • readValue

        public java.lang.Object readValue()
                                   throws java.io.IOException
        Method for reading a "simple" Object of type indicated by JSON content: Map for JSON Object, Map for JSON Array (or, Object[] if so configured), String for JSON String value and so on.
        Throws:
        java.io.IOException
      • readMap

        public java.util.Map<java.lang.Object,​java.lang.Object> readMap()
                                                                       throws java.io.IOException
        Method for reading a JSON Object from input and building a Map out of it. Note that if input does NOT contain a JSON Object, JSONObjectException will be thrown.
        Throws:
        java.io.IOException
      • readList

        public java.util.List<java.lang.Object> readList()
                                                  throws java.io.IOException
        Method for reading a JSON Array from input and building a List out of it. Note that if input does NOT contain a JSON Array, JSONObjectException will be thrown.
        Throws:
        java.io.IOException
      • readArray

        public java.lang.Object[] readArray()
                                     throws java.io.IOException
        Method for reading a JSON Array from input and building a Object[] out of it. Note that if input does NOT contain a JSON Array, JSONObjectException will be thrown.
        Throws:
        java.io.IOException
      • readBean

        public <T> T readBean​(java.lang.Class<T> type)
                       throws java.io.IOException
        Method for reading a JSON Object from input and building a Bean of specified type out of it; Bean has to conform to standard Java Bean specification by having setters for passing JSON Object properties.
        Throws:
        java.io.IOException
      • readArrayOf

        public <T> T[] readArrayOf​(java.lang.Class<T> type)
                            throws java.io.IOException
        Throws:
        java.io.IOException
      • readListOf

        public <T> java.util.List<T> readListOf​(java.lang.Class<T> type)
                                         throws java.io.IOException
        Method for reading a JSON Array from input and building a List out of it. Note that if input does NOT contain a JSON Array, JSONObjectException will be thrown.
        Throws:
        java.io.IOException
      • _mapBuilder

        protected MapBuilder _mapBuilder​(java.lang.Class<?> mapType)
      • _collectionBuilder

        protected CollectionBuilder _collectionBuilder​(java.lang.Class<?> collType)