Class JsonParser
- All Implemented Interfaces:
- AnnotationProvider,- JsonMetaProvider
- Direct Known Subclasses:
- Json5Parser,- JsonParser.Strict
Media types
 Handles 
Description
This parser uses a state machine, which makes it very fast and efficient. It parses JSON in about 70% of the time that it takes the built-in Java DOM parsers to parse equivalent XML.
This parser handles all valid JSON syntax. In addition, when strict mode is disable, the parser also handles the following:
- 
      Javascript comments (both /*and//) are ignored.
- Both single and double quoted strings.
- 
      Automatically joins concatenated strings (e.g. "aaa" +'bbb' 
- Unquoted attributes and values.
Also handles negative, decimal, hexadecimal, octal, and double numbers, including exponential notation.
This parser handles the following input, and automatically returns the corresponding Java class.
- 
      JSON objects ("{...}" ) are converted toJsonMaps. Note: If a_type ='xxx' BeanContext.Builder.typePropertyName(String)setting for more information about parsing beans from JSON.
- 
      JSON arrays ("[...]" ) are converted toJsonLists.
- 
      JSON string literals ("'xyz'" ) are converted toStrings.
- 
      JSON numbers ("123" , including octal/hexadecimal/exponential notation) are converted toIntegers,Longs,Floats, orDoublesdepending on whether the number is decimal, and the size of the number.
- 
      JSON booleans ("false" ) are converted toBooleans.
- 
      JSON nulls ("null" ) are converted tonull .
- 
      Input consisting of only whitespace or JSON comments are converted to null .
Input can be any of the following:
- 
      "{...}" - Converted to anJsonMapor an instance of a Java bean if a_type attribute is present.
- 
      "[...]" - Converted to anJsonList.
- 
      "123..." - Converted to aNumber(eitherInteger,Long,Float, orDouble).
- 
      "true" /"false" - Converted to aBoolean.
- 
      "null" - Returnsnull .
- 
      "'xxx'" - Converted to aString.
- 
      "\"xxx\"" - Converted to aString.
- 
      "'xxx' + \"yyy\"" - Converted to a concatenatedString.
 TIP:  If you know you're parsing a JSON object or array, it can be easier to parse it using the
 JsonMap(CharSequence) or JsonList(CharSequence) constructors instead of using this class.
 The end result should be the same.
 
Notes:
- This class is thread safe and reusable.
See Also:
- 
Nested Class SummaryNested ClassesModifier and TypeClassDescriptionstatic classBuilder class.static classDefault parser, strict mode.Nested classes/interfaces inherited from class org.apache.juneau.parser.ParserParser.Null
- 
Field SummaryFieldsModifier and TypeFieldDescriptionstatic final JsonParserDefault parser, all default settings.static final JsonParserDefault parser, all default settings.Fields inherited from class org.apache.juneau.ContextCONTEXT_APPLY_FILTERFields inherited from interface org.apache.juneau.AnnotationProviderDISABLE_ANNOTATION_CACHING
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptioncopy()Creates a builder from this context object.static JsonParser.Buildercreate()Creates a new builder for this object.Create a session builder based on the properties defined on this context.Returns the language-specific metadata on the specified bean property.getJsonClassMeta(ClassMeta<?> cm) Returns the language-specific metadata on the specified class.Returns a session to use for this context.protected final booleanValidate end.Methods inherited from class org.apache.juneau.parser.ReaderParsergetFileCharset, getStreamCharset, isReaderParser, propertiesMethods inherited from class org.apache.juneau.parser.ParsercanHandle, createParserBuilder, doParse, getDebugOutputLines, getListener, getMediaTypes, getPrimaryMediaType, isAutoCloseStreams, isStrict, isTrimStrings, isUnbuffered, parse, parse, parse, parse, parse, parse, parseArgs, parseIntoCollection, parseIntoMapMethods inherited from class org.apache.juneau.BeanContextablegetBeanContextMethods inherited from class org.apache.juneau.ContextcreateBuilder, firstAnnotation, firstAnnotation, firstAnnotation, firstAnnotation, firstDeclaredAnnotation, forEachAnnotation, forEachAnnotation, forEachAnnotation, forEachAnnotation, forEachDeclaredAnnotation, hasAnnotation, hasAnnotation, hasAnnotation, hasAnnotation, init, isDebug, lastAnnotation, lastAnnotation, lastAnnotation, lastAnnotation, lastDeclaredAnnotation, toStringMethods inherited from class java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.apache.juneau.AnnotationProviderfirstAnnotation, firstAnnotation, firstAnnotation, firstAnnotation, firstDeclaredAnnotation, forEachAnnotation, forEachAnnotation, forEachAnnotation, forEachAnnotation, forEachDeclaredAnnotation, lastAnnotation, lastAnnotation, lastAnnotation, lastAnnotation, lastDeclaredAnnotation
- 
Field Details- 
DEFAULTDefault parser, all default settings.
- 
DEFAULT_STRICTDefault parser, all default settings.
 
- 
- 
Constructor Details- 
JsonParserConstructor.- Parameters:
- builder- The builder for this object.
 
 
- 
- 
Method Details- 
createCreates a new builder for this object.- Returns:
- A new builder.
 
- 
copyDescription copied from class:ContextCreates a builder from this context object.Builders are used to define new contexts (e.g. serializers, parsers) based on existing configurations. 
- 
createSessionDescription copied from class:ContextCreate a session builder based on the properties defined on this context.Use this method for creating sessions where you want to override basic settings. Otherwise, use Context.getSession()directly.- Overrides:
- createSessionin class- ReaderParser
- Returns:
- A new session builder.
 
- 
getSessionDescription copied from class:ContextReturns a session to use for this context.Note that subclasses may opt to return a reusable non-modifiable session. - Overrides:
- getSessionin class- ReaderParser
- Returns:
- A new session object.
 
- 
getJsonClassMetaDescription copied from interface:JsonMetaProviderReturns the language-specific metadata on the specified class.- Specified by:
- getJsonClassMetain interface- JsonMetaProvider
- Parameters:
- cm- The class to return the metadata on.
- Returns:
- The metadata.
 
- 
getJsonBeanPropertyMetaDescription copied from interface:JsonMetaProviderReturns the language-specific metadata on the specified bean property.- Specified by:
- getJsonBeanPropertyMetain interface- JsonMetaProvider
- Parameters:
- bpm- The bean property to return the metadata on.
- Returns:
- The metadata.
 
- 
isValidateEndValidate 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:
 
 
-