Class JsonParserSession
- All Implemented Interfaces:
BeanSession,ConverterSession,ArrayRecordReadable,RecordReadable,TokenReadable
- Direct Known Subclasses:
Json5ParserSession,JsonlParserSession
JsonParser.
Notes:
- This class is not thread safe and is typically discarded after one use.
See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classBuilder class.static final classConcrete default builder leaf for the non-subclassedcreate()path (CRTP terminal). -
Field Summary
Fields inherited from class org.apache.juneau.marshall.parser.ParserSession
DEFAULT_MAX_PARSE_DEPTHFields inherited from class org.apache.juneau.marshall.MarshallingSession
NAME_PROPERTY_NAME -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedJsonParserSession(JsonParserSession.Builder<?> builder) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionprotected booleanReturns whether trailing commas are accepted before] /} in the databind path.protected booleanReturns whether non-string types can be coerced to strings usingnewInstanceFromString().static JsonParserSession.Builder<?>create(JsonParser ctx) Creates a new builder for this object.protected <T> TdoRead(ParserPipe pipe, ClassMeta<T> type) Workhorse method.protected <E> Collection<E>doReadIntoCollection(ParserPipe pipe, Collection<E> c, Type elementType) Implementation method.protected <K,V> Map<K, V> doReadIntoMap(ParserPipe pipe, Map<K, V> m, Type keyType, Type valueType) Implementation method.protected JsonClassMetagetJsonClassMeta(ClassMeta<?> cm) Returns the language-specific metadata on the specified class.protected booleanisCommentOrWhitespace(int cp) Returnstrue if the specified character is whitespace or '/'.protected booleanisNumberStartChar(int c) Returnstrue if the specified character can start a number value.protected booleanValidate end.protected booleanisWhitespace(int cp) Returnstrue if the specified character is whitespace.protected MarshalledListCreates a generic list for parser-driven list population.protected MarshalledMapCreates a string-keyed generic map for parser-driven map population.protected voidHook called when empty input is detected inreadAnything().protected voidHook called when a missing value is detected inreadAnything().readArrayRecords(Object input) Streaming array-elementRecordReaderbacked byJsonTokenReader.protected Stringprotected voidreadKeyword(String keyword, ParserReader r) protected NumberreadNumber(ParserReader r, Class<? extends Number> type) protected NumberreadNumber(ParserReader r, String s, Class<? extends Number> type) protected StringreadTokens(Object input) Opens a low-level pull-parser cursor over a JSON document, bound to this session's liveBeanSession/MarshallingContext.protected voidprotected voidMethods inherited from class org.apache.juneau.marshall.parser.ReaderParserSession
create, createPipe, getStreamCharset, isReaderParser, propertiesMethods inherited from class org.apache.juneau.marshall.parser.ParserSession
allocateLocal, cast, checkRequired, convertAttrToType, create, doReadToBeanConsumer, enterParseDepth, exitParseDepth, getCalendarFormat, getClassMeta, getDateFormat, getDebugOutputLines, getDurationFormat, getInputAsString, getJavaMethod, getLastLocation, getListener, getListener, getListenerClass, getLocaleFormat, getNulls, getOuter, getPeriodFormat, getPosition, getSchema, getStringBuilder, getTemporalFormat, getTimeZoneFormat, isAutoCloseStreams, isTrimStrings, isUnbuffered, mark, onBeanSetterException, onUnknownProperty, parentBean, read, read, read, read, read, read, readArgs, readCalendar, readDate, readDuration, readIntoCollection, readIntoMap, readPeriod, readTemporal, readToBeanConsumer, returnStringBuilder, setCurrentClass, setCurrentProperty, setName, setParent, setPipe, swapParentBean, trim, trim, unmark, unswapMethods inherited from class org.apache.juneau.marshall.MarshallingSession
addWarning, convertToMemberType, convertToMemberType, convertToMemberType, convertToType, convertToType, convertToType, convertToType, create, get, getActiveView, getAnnotationProvider, getArgsClassMeta, getBeanClassVisibility, getBeanConstructorVisibility, getBeanDictionary, getBeanFieldVisibility, getBeanMeta, getBeanMethodVisibility, getBeanRegistry, getBeanTypePropertyName, getBeanTypePropertyName, getClassLoader, getClassMeta, getClassMeta, getClassMetaForObject, getClassMetaForObject, getLocale, getMarshallingContext, getMediaType, getNotBeanClasses, getNotBeanPackagesNames, getPropertyNamer, getSwaps, getTimeZone, getTimeZoneId, isBean, isBean, isBeanMapPutReturnsOldValue, isBeansRequireDefaultConstructor, isBeansRequireSerializable, isBeansRequireSettersForGetters, isBeansRequireSomeProperties, isFindFluentSetters, isIgnoreInvocationExceptionsOnGetters, isIgnoreInvocationExceptionsOnSetters, isIgnoreMissingSetters, isIgnoreUnknownBeanProperties, isIgnoreUnknownNullBeanProperties, isPropertyInActiveView, isRecordComponentOrder, isUnsortedProperties, isUseInterfaceProxies, isUseJavaBeanIntrospector, isValidateSchema, newBean, newBean, newBeanMap, newBeanMap, newGenericMap, object, parseToList, parseToMap, string, toArray, toBeanMap, toBeanMap, toBeanMapMethods inherited from class org.apache.juneau.marshall.ContextSession
checkForWarnings, getContext, getSessionProperties, getWarnings, isDebug, toStringMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.apache.juneau.marshall.stream.ArrayRecordReadable
isArrayRecordStreaming, readArrayRecordsMethods inherited from interface org.apache.juneau.commons.conversion.ConverterSession
getMethods inherited from interface org.apache.juneau.marshall.stream.RecordReadable
isRecordStreamingMethods inherited from interface org.apache.juneau.marshall.stream.TokenReadable
readRecords
-
Constructor Details
-
JsonParserSession
Constructor.- Parameters:
builder- The builder for this object.
-
-
Method Details
-
create
Creates a new builder for this object.- Parameters:
ctx- The context creating this session.- Returns:
- A new builder.
-
readFieldName
- Throws:
IOExceptionParseException
-
readKeyword
- Throws:
IOExceptionParseException
-
readNumber
protected Number readNumber(ParserReader r, Class<? extends Number> type) throws IOException, ParseException - Throws:
IOExceptionParseException
-
readNumber
protected Number readNumber(ParserReader r, String s, Class<? extends Number> type) throws ParseException - Throws:
ParseException
-
readString
- Throws:
IOExceptionParseException
-
skipComments
- Throws:
ParseExceptionIOException
-
skipCommentsAndSpace
- Throws:
IOExceptionParseException
-
doRead
protected <T> T doRead(ParserPipe pipe, ClassMeta<T> type) throws IOException, ParseException, ExecutableException Description copied from class:ParserSessionWorkhorse method.Subclasses are expected to implement this method or
Parser.doRead(ParserSession,ParserPipe,ClassMeta).The default implementation of this method simply calls
Parser.doRead(ParserSession,ParserPipe,ClassMeta).- Overrides:
doReadin classParserSession- Type Parameters:
T- The class type of the object to create.- Parameters:
pipe- Where to get the input from.type- The class type of the object to create. Ifnull orObject., object type is based on what's being parsed. For example, when parsing JSON text, it may return aclass String ,Number ,JsonMap , etc...- Returns:
- The parsed object.
- Throws:
IOException- Thrown by underlying stream.ParseException- Malformed input encountered.ExecutableException- Exception occurred on invoked constructor/method/field.
-
readTokens
Opens a low-level pull-parser cursor over a JSON document, bound to this session's liveBeanSession/MarshallingContext.The cursor is purely structural — object swaps and
@Schemaannotations are not applied at this layer. SeeTokenReaderfor the contract.Builder properties honored:
The structurally-applicable subset flows through to the cursor:autoCloseStreams ,unbuffered ,trimStrings (applied toTokenType.VALUE_STRINGandTokenType.FIELD_NAMEvalues), and theReaderParserstream/file charsets.Builder properties NOT honored:
validateEnd() (the cursor leaves end-of-input checking to the caller),listener(...) /debugOutputLines(...) ,consumes(...) , object swaps, and@Schemaannotations (only applied on the POJO databind path).- Specified by:
readTokensin interfaceTokenReadable- Parameters:
input- The input. AcceptsReader,CharSequence,InputStream, or.byte []- Returns:
- A new
JsonTokenReader. - Throws:
IOException- If a problem occurred opening the underlying input.
-
readArrayRecords
Streaming array-elementRecordReaderbacked byJsonTokenReader. Memory is O(1) in the array length — elements are bound on demand using this live session.- Specified by:
readArrayRecordsin interfaceArrayRecordReadable- Parameters:
input- The input.- Returns:
- A new element-streamed
RecordReader. - Throws:
IOException- If a problem occurred opening the underlying input.
-
doReadIntoCollection
protected <E> Collection<E> doReadIntoCollection(ParserPipe pipe, Collection<E> c, Type elementType) throws IOException, ParseException, ExecutableException Description copied from class:ParserSessionImplementation method.Default implementation throws an
UnsupportedOperationException.- Overrides:
doReadIntoCollectionin classParserSession- Type Parameters:
E- The element type.- Parameters:
pipe- The parser input.c- The collection being loaded.elementType- The class type of the elements, ornull to default to whatever is being parsed.- Returns:
- The same collection that was passed in to allow this method to be chained.
- Throws:
IOExceptionParseExceptionExecutableException
-
doReadIntoMap
protected <K,V> Map<K,V> doReadIntoMap(ParserPipe pipe, Map<K, V> m, Type keyType, Type valueType) throws IOException, ParseException, ExecutableExceptionDescription copied from class:ParserSessionImplementation method.Default implementation throws an
UnsupportedOperationException.- Overrides:
doReadIntoMapin classParserSession- Type Parameters:
K- The key type.V- The value type.- Parameters:
pipe- The parser input.m- The map being loaded.keyType- The class type of the keys, ornull to default toString..class valueType- The class type of the values, ornull to default to whatever is being parsed.- Returns:
- The same map that was passed in to allow this method to be chained.
- Throws:
IOExceptionParseExceptionExecutableException
-
getJsonClassMeta
Returns the language-specific metadata on the specified class.- Parameters:
cm- The class to return the metadata on.- Returns:
- The metadata.
-
isNumberStartChar
Returnstrue if the specified character can start a number value.JSON numbers start with a digit,
- , or. . JSON5 subclasses also accept+ ,I (Infinity ), andN (NaN ).- Parameters:
c- The next non-whitespace character.- Returns:
true if a number lexeme should be read from this character.
-
isCommentOrWhitespace
Returnstrue if the specified character is whitespace or '/'.- Parameters:
cp- The codepoint.- Returns:
true if the specified character is whitespace or '/'.
-
isValidateEnd
Validate end.- Returns:
true if after parsing a POJO from the input, verifies that the remaining input in the stream consists of only comments or whitespace.- See Also:
-
isWhitespace
Returnstrue if the specified character is whitespace.Only 0x20 (space), 0x09 (tab), 0x0A (line feed) and 0x0D (carriage return) are considered whitespace.
- Parameters:
cp- The codepoint.- Returns:
true if the specified character is whitespace.
-
onEmptyInput
Hook called when empty input is detected inreadAnything().- Throws:
ParseException- Always in strict mode.
-
onMissingValue
Hook called when a missing value is detected inreadAnything().- Throws:
ParseException- Always in strict mode.
-
allowsTrailingComma
Returns whether trailing commas are accepted before] /} in the databind path.Default returns
false (strict RFC-8259 JSON).Json5ParserSessionoverrides this totrue for the JSON5 dialect.- Returns:
true if a trailing comma should be silently accepted.
-
canCoerceNonStringToString
Returns whether non-string types can be coerced to strings usingnewInstanceFromString().- Returns:
- Always
falsefor standard JSON.
-
newGenericMap
Description copied from class:MarshallingSessionCreates a string-keyed generic map for parser-driven map population.This is the main factory hook overridden by per-marshaller parser sessions to return their flavored
XMapvariant (for example,JsonParserSessionreturnsJsonMap;Json5ParserSessionreturnsJson5Map).- Overrides:
newGenericMapin classMarshallingSession- Returns:
- A new map.
-
newGenericList
Description copied from class:MarshallingSessionCreates a generic list for parser-driven list population.Per-marshaller parser sessions override this hook to return their flavored
XListvariant (for example,JsonParserSessionreturnsJsonList;Json5ParserSessionreturnsJson5List).- Overrides:
newGenericListin classMarshallingSession- Returns:
- A new list.
-