Class JsonParser

  • All Implemented Interfaces:
    java.lang.AutoCloseable

    public class JsonParser
    extends java.lang.Object
    implements java.lang.AutoCloseable
    This class provides methods to read a JSON input.
    Methods starting with get will return an item related to the previous next() return value.
    Methods starting with read involve one or more internal calls to next() method to read complex values. This is an example of hot to use it:
     try(JsonParser parser = new JsonParser(reader)){
       while(parser.hasNext()){
         switch(parser.next()){
         case KEY_NAME:
           parser.getString();
           break;
         case VALUE_STRING:
           parser.getString();
           break;
         }
       }
     }
      
    • Constructor Summary

      Constructors 
      Constructor Description
      JsonParser​(java.io.Reader reader)  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void close()  
      java.math.BigDecimal getBigDecimal()  
      boolean getBoolean()  
      double getDouble()  
      int getInt()  
      JsonParser.JsonLocation getLocation()  
      long getLong()  
      java.lang.String getString()
      This method should be called to return JSON field names or JSON values.
      If JSON value is a JSON Objects {link readJSONObject() will return the JSON Object as string.
      If JSON value is a JSON Array {link readJSONArray() will return the JSON Array as string.
      java.lang.String getStringValue()
      Calling this method avoid calling {link #next()} after the previous call returned Event.KEY_NAME to read a JSON string values.
      boolean hasNext()  
      boolean isIntegralNumber()
      This method help to identify if the JSON number is integral by not having a fractional or exponential part.
      JsonParser.Event next()
      This method returned the next JsonParser.Event recognized by the parser.
      If event is Event.KEY_NAME calling getString() will return JSON field name.
      If event is Event.VALUE_STRING calling getString() will return JSON field value as string.
      double[][] readArrayOfDoubleArray()
      This method simplify the process of reading a JSON value as a double[][].
      java.lang.String[][] readArrayOfStringArray()
      This method simplify the process of reading a JSON value as a String[][].
      double[] readDoubleArray()
      This method simplify the process of reading a JSON value as a double[].
      int[] readIntArray()
      This method simplify the process of reading a JSON value as int[].
      java.lang.String readJSONArray()
      This method will advance the parser to the end of array and return the array value as string.
      java.lang.String readJSONObject()
      This method will advance the parser to the end of JSON object and return the object value as string.
      long[] readLongArray()
      This method simplify the process of reading a JSON value as a long[].
      java.lang.String[] readStringArray()
      This method simplify the process of reading a JSON value as a String[].
      static java.lang.String writeValueAsIndentedString​(java.lang.String str)
      Receive a JSON String and return a new indented JSON String.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait