Package com.blackrook.json
Class JSONReader
java.lang.Object
com.blackrook.json.JSONReader
A class for reading JSON data into
JSONObject
s.- Author:
- Matthew Tropiano
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic JSONObject
readJSON
(InputStream in) Reads in a new JSONObject from an InputStream.static JSONObject
Reads in a new JSONObject from a Reader.static <T> T
readJSON
(Class<T> clazz, InputStream in) Reads in a new object from an InputStream.static <T> T
readJSON
(Class<T> clazz, InputStream in, JSONConverterSet converterSet) Reads in a new object from an InputStream.static <T> T
Reads in a new object from a Reader.static <T> T
readJSON
(Class<T> clazz, Reader reader, JSONConverterSet converterSet) Reads in a new object from a Reader.static <T> T
Reads in a new object from a string of characters and returns it as a new object converted from the JSON.static <T> T
readJSON
(Class<T> clazz, String data, JSONConverterSet converterSet) Reads in a new object from a string of characters and returns it as a new object converted from the JSON.static JSONObject
Reads in a new JSONObject from a string of characters.
-
Constructor Details
-
JSONReader
public JSONReader()
-
-
Method Details
-
readJSON
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
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
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
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
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
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.
-