Package org.jmxtrans.agent.util.json
Class JsonParser
java.lang.Object
org.jmxtrans.agent.util.json.JsonParser
public class JsonParser extends Object
A streaming parser for JSON text. The parser reports all events to a given handler.
-
Constructor Summary
Constructors Constructor Description JsonParser(JsonHandler<?,?> handler)Creates a new JsonParser with the given handler. -
Method Summary
Modifier and Type Method Description voidparse(Reader reader)Reads the entire input from the given reader and parses it as JSON.voidparse(Reader reader, int buffersize)Reads the entire input from the given reader and parses it as JSON.voidparse(String string)Parses the given input string.
-
Constructor Details
-
JsonParser
Creates a new JsonParser with the given handler. The parser will report all parser events to this handler.- Parameters:
handler- the handler to process parser events
-
-
Method Details
-
parse
Parses the given input string. The input must contain a valid JSON value, optionally padded with whitespace.- Parameters:
string- the input string, must be valid JSON- Throws:
ParseException- if the input is not valid JSON
-
parse
Reads the entire input from the given reader and parses it as JSON. The input must contain a valid JSON value, optionally padded with whitespace.Characters are read in chunks into a default-sized input buffer. Hence, wrapping a reader in an additional
BufferedReaderlikely won't improve reading performance.- Parameters:
reader- the reader to read the input from- Throws:
IOException- if an I/O error occurs in the readerParseException- if the input is not valid JSON
-
parse
Reads the entire input from the given reader and parses it as JSON. The input must contain a valid JSON value, optionally padded with whitespace.Characters are read in chunks into an input buffer of the given size. Hence, wrapping a reader in an additional
BufferedReaderlikely won't improve reading performance.- Parameters:
reader- the reader to read the input frombuffersize- the size of the input buffer in chars- Throws:
IOException- if an I/O error occurs in the readerParseException- if the input is not valid JSON
-