Package org.apache.groovy.json.internal
Class JsonParserCharArray
java.lang.Object
org.apache.groovy.json.internal.BaseJsonParser
org.apache.groovy.json.internal.JsonParserCharArray
- All Implemented Interfaces:
JsonParser
- Direct Known Subclasses:
JsonFastParser,JsonParserLax
Converts an input JSON String into Java objects works with String or char array
as input. Produces an Object which can be any of the basic JSON types mapped to Java.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected charCharacter at the current parser position.protected intCurrent position withincharArray.protected char[]Character buffer currently being parsed.protected static char[]Character buffer for thefalseliteral.protected static final char[]Character buffer for thenullliteral.protected static final char[]Character buffer for thetrueliteral.Fields inherited from class org.apache.groovy.json.internal.BaseJsonParser
ALPHA_0, ALPHA_1, ALPHA_2, ALPHA_3, ALPHA_4, ALPHA_5, ALPHA_6, ALPHA_7, ALPHA_8, ALPHA_9, bufSize, charset, CLOSED_BRACKET, CLOSED_CURLY, COLON, COMMA, DECIMAL_POINT, DOUBLE_QUOTE, ESCAPE, internedKeysCache, internKeys, LETTER_BIG_E, LETTER_E, MINUS, PLUS -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected final voidThrows aJsonExceptionfor the current location.protected final charReturns the current character in the input buffer.protected final booleanConsumes thefalseliteral.protected ObjectdecodeFromChars(char[] cs) Initializes parser state and decodes a character buffer.protected final ListDecodes a JSON array from the current position.protected final ObjectDecodes a JSON object from the current position.protected final ObjectConsumes thenullliteral.protected final booleanConsumes thetrueliteral.protected ObjectDecodes the next JSON value.protected StringexceptionDetails(String message) Builds an error message using the current parser position.protected final booleanChecks whether the current index is still within the buffer.protected final booleanhasMore()Checks whether more characters remain after the current index.protected final charnextChar()Advances to the next character in the input buffer.parse(char[] chars) Parses JSON from a character array.protected final voidAdvances past JSON whitespace characters.Methods inherited from class org.apache.groovy.json.internal.BaseJsonParser
charDescription, findEndQuote, hasEscapeChar, isDecimalChar, isDelimiter, isDoubleQuote, isEscape, isNumberDigit, parse, parse, parse, parse, parse, parse, parse, parse, setCharset
-
Field Details
-
charArray
protected char[] charArrayCharacter buffer currently being parsed. -
__index
protected int __indexCurrent position withincharArray. -
__currentChar
protected char __currentCharCharacter at the current parser position. -
NULL
protected static final char[] NULLCharacter buffer for thenullliteral. -
TRUE
protected static final char[] TRUECharacter buffer for thetrueliteral. -
FALSE
protected static char[] FALSECharacter buffer for thefalseliteral.
-
-
Constructor Details
-
JsonParserCharArray
public JsonParserCharArray()
-
-
Method Details
-
decodeFromChars
Initializes parser state and decodes a character buffer.- Parameters:
cs- JSON content to parse- Returns:
- parsed Groovy JSON value
-
hasMore
protected final boolean hasMore()Checks whether more characters remain after the current index.- Returns:
truewhen another character can be consumed
-
hasCurrent
protected final boolean hasCurrent()Checks whether the current index is still within the buffer.- Returns:
truewhen the current position is valid
-
skipWhiteSpace
protected final void skipWhiteSpace()Advances past JSON whitespace characters. -
nextChar
protected final char nextChar()Advances to the next character in the input buffer.- Returns:
- next character, or
0when the buffer is exhausted
-
exceptionDetails
Builds an error message using the current parser position.- Parameters:
message- parser-specific message- Returns:
- formatted error details
-
decodeJsonObject
Decodes a JSON object from the current position.- Returns:
- parsed object as a
LazyMap
-
complain
Throws aJsonExceptionfor the current location.- Parameters:
complaint- message describing the parse failure
-
decodeValue
Decodes the next JSON value.- Returns:
- parsed Groovy JSON value
-
decodeNull
Consumes thenullliteral.- Returns:
null
-
decodeTrue
protected final boolean decodeTrue()Consumes thetrueliteral.- Returns:
true
-
decodeFalse
protected final boolean decodeFalse()Consumes thefalseliteral.- Returns:
false
-
decodeJsonArray
Decodes a JSON array from the current position.- Returns:
- parsed array contents
-
currentChar
protected final char currentChar()Returns the current character in the input buffer.- Returns:
- current character, or
0when the index is past the end
-
parse
Parses JSON from a character array.- Parameters:
chars- JSON content to parse- Returns:
- parsed Groovy JSON value
-