Class JSONReader

java.lang.Object
com.blackrook.json.JSONReader

public class JSONReader extends Object
A class for reading JSON data into JSONObjects.
Author:
Matthew Tropiano
  • Constructor Details

    • JSONReader

      public JSONReader()
  • Method Details

    • readJSON

      public static JSONObject readJSON(Reader reader) throws IOException
      Reads in a new JSONObject from a Reader. This does not close the stream after reading, and reads the first structure that it finds.
      Parameters:
      reader - the reader to read from.
      Returns:
      the parsed JSONObject.
      Throws:
      IOException - if the stream can't be read, or a read error occurs.
      JSONConversionException - if a parsing error occurs, or the JSON is malformed.
    • readJSON

      public static JSONObject readJSON(InputStream in) throws IOException
      Reads in a new JSONObject from an InputStream. This does not close the stream after reading, and reads the first structure that it finds.
      Parameters:
      in - the input stream to read from.
      Returns:
      the parsed JSONObject.
      Throws:
      IOException - if the stream can't be read, or an error occurs.
      JSONConversionException - if a parsing error occurs, or the JSON is malformed.
    • readJSON

      public static JSONObject readJSON(String data) throws IOException
      Reads in a new JSONObject from a string of characters.
      Parameters:
      data - the string to read.
      Returns:
      the parsed JSONObject.
      Throws:
      IOException - if the string can't be read, or a read error occurs.
      JSONConversionException - if a parsing error occurs, or the JSON is malformed.
    • readJSON

      public static <T> T readJSON(Class<T> clazz, Reader reader, JSONConverterSet converterSet) throws IOException
      Reads in a new object from a Reader. This does not close the stream after reading, and reads the first structure that it finds and returns it as a new object converted from the JSON.
      Type Parameters:
      T - the returned class type.
      Parameters:
      converterSet - the converter set to use for conversion of certain specific types.
      clazz - the class type to read.
      reader - the reader to read from.
      Returns:
      the applied object, already converted.
      Throws:
      IOException - if the stream can't be read, or a read error occurs.
      JSONConversionException - if a parsing error occurs, or the JSON is malformed.
      Since:
      1.3.0
    • readJSON

      public static <T> T readJSON(Class<T> clazz, InputStream in, JSONConverterSet converterSet) throws IOException
      Reads in a new object from an InputStream. This does not close the stream after reading, and reads the first structure that it finds and returns it as a new object converted from the JSON.
      Type Parameters:
      T - the returned class type.
      Parameters:
      converterSet - the converter set to use for conversion of certain specific types.
      clazz - the class type to read.
      in - the input stream to read from.
      Returns:
      the applied object, already converted.
      Throws:
      IOException - if the stream can't be read, or an error occurs.
      JSONConversionException - if a parsing error occurs, or the JSON is malformed.
      Since:
      1.3.0
    • readJSON

      public static <T> T readJSON(Class<T> clazz, String data, JSONConverterSet converterSet) throws IOException
      Reads in a new object from a string of characters and returns it as a new object converted from the JSON.
      Type Parameters:
      T - the returned class type.
      Parameters:
      converterSet - the converter set to use for conversion of certain specific types.
      clazz - the class type to read.
      data - the string to read.
      Returns:
      the applied object, already converted.
      Throws:
      IOException - if the string can't be read, or a read error occurs.
      JSONConversionException - if a parsing error occurs, or the JSON is malformed.
      Since:
      1.3.0
    • readJSON

      public static <T> T readJSON(Class<T> clazz, Reader reader) throws IOException
      Reads in a new object from a Reader. This does not close the stream after reading, and reads the first structure that it finds and returns it as a new object converted from the JSON.
      Type Parameters:
      T - the returned class type.
      Parameters:
      clazz - the class type to read.
      reader - the reader to read from.
      Returns:
      the applied object, already converted.
      Throws:
      IOException - if the stream can't be read, or a read error occurs.
      JSONConversionException - if a parsing error occurs, or the JSON is malformed.
    • readJSON

      public static <T> T readJSON(Class<T> clazz, InputStream in) throws IOException
      Reads in a new object from an InputStream. This does not close the stream after reading, and reads the first structure that it finds and returns it as a new object converted from the JSON.
      Type Parameters:
      T - the returned class type.
      Parameters:
      clazz - the class type to read.
      in - the input stream to read from.
      Returns:
      the applied object, already converted.
      Throws:
      IOException - if the stream can't be read, or an error occurs.
      JSONConversionException - if a parsing error occurs, or the JSON is malformed.
    • readJSON

      public static <T> T readJSON(Class<T> clazz, String data) throws IOException
      Reads in a new object from a string of characters and returns it as a new object converted from the JSON.
      Type Parameters:
      T - the returned class type.
      Parameters:
      clazz - the class type to read.
      data - the string to read.
      Returns:
      the applied object, already converted.
      Throws:
      IOException - if the string can't be read, or a read error occurs.
      JSONConversionException - if a parsing error occurs, or the JSON is malformed.