- All Implemented Interfaces:
Serializable,Snapshottable<TokenStreamFactory>,Versioned
TokenStreamFactory implementation that will create
token readers ("parsers") and writers ("generators") for handling
JSON-encoded content.
Note that this class used to reside at main tools.jackson.core
in 2.x, but moved here to denote its changed role as implementation,
not base class for factories.
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class tools.jackson.core.base.DecorableTSFactory
DecorableTSFactory.DecorableTSFBuilder<F extends TokenStreamFactory,T extends TSFBuilder<F, T>> Nested classes/interfaces inherited from class tools.jackson.core.TokenStreamFactory
TokenStreamFactory.Feature -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final ByteQuadsCanonicalizerAlternative to the basic symbol table, some stream-based parsers use different name canonicalization method.protected final CharacterEscapesDefinition of custom character escapes to use for generators created by this factory, if any.protected final intOptional threshold used for automatically escaping character above certain character code value: either0to indicate that no threshold is specified, or value at or above 127 to indicate last character code that is NOT automatically escaped (but depends on other configuration rules for checking).protected final charCharacter used for quoting property names (if property name quoting has not been disabled withJsonWriteFeature.QUOTE_PROPERTY_NAMES) and JSON String values.protected final CharsToNameCanonicalizerEach factory comes equipped with a shared root symbol table.protected final SerializableStringSeparator used between root-level values, if any; null indicates "do not add separator".static final charstatic final SerializableStringstatic final StringName used to identify JSON format (and returned bygetFormatName()Fields inherited from class tools.jackson.core.base.DecorableTSFactory
_generatorDecorators, _inputDecorator, _outputDecoratorFields inherited from class tools.jackson.core.TokenStreamFactory
_errorReportConfiguration, _factoryFeatures, _formatReadFeatures, _formatWriteFeatures, _recyclerPool, _streamReadConstraints, _streamReadFeatures, _streamWriteConstraints, _streamWriteFeatures, DEFAULT_FACTORY_FEATURE_FLAGS, DEFAULT_STREAM_READ_FEATURE_FLAGS, DEFAULT_STREAM_WRITE_FEATURE_FLAGS, EMPTY_WRITE_CONTEXT -
Constructor Summary
ConstructorsModifierConstructorDescriptionDefault constructor used to create factory instances.protectedJsonFactory(JsonFactory src) Copy constructor.protectedConstructors used byJsonFactoryBuilderfor instantiation. -
Method Summary
Modifier and TypeMethodDescriptionprotected JsonGenerator_createGenerator(ObjectWriteContext writeCtxt, IOContext ioCtxt, Writer out) Overridable factory method that actually instantiates generator for givenWriterand context object.protected IOContext_createNonBlockingContext(Object srcRef) protected JsonParser_createParser(ObjectReadContext readCtxt, IOContext ioCtxt, byte[] data, int offset, int len) protected JsonParser_createParser(ObjectReadContext readCtxt, IOContext ioCtxt, char[] data, int offset, int len, boolean recyclable) protected JsonParser_createParser(ObjectReadContext readCtxt, IOContext ioCtxt, DataInput input) protected JsonParser_createParser(ObjectReadContext readCtxt, IOContext ioCtxt, InputStream in) protected JsonParser_createParser(ObjectReadContext readCtxt, IOContext ioCtxt, Reader r) protected JsonGenerator_createUTF8Generator(ObjectWriteContext writeCtxt, IOContext ioCtxt, OutputStream out) Overridable factory method that actually instantiates generator for givenOutputStreamand context object, using UTF-8 encoding.static JsonFactoryBuilderbuilder()Main factory method to use for constructingJsonFactoryinstances with different configuration.static JsonFactoryBuilderFactory method to use for constructingJsonFactoryinstances with different configuration.booleanIntrospection method that can be used to check whether this factory can create non-blocking parsers: parsers that do not use blocking I/O abstractions but instead use aNonBlockingInputFeeder.booleancanUseSchema(FormatSchema schema) Method that can be used to quickly check whether given schema is something that parsers and/or generators constructed by this factory could use.constructCINameMatcher(List<Named> matches, boolean alreadyInterned, Locale locale) Factory method for constructing case-insensitivePropertyNameMatcherfor given names.constructNameMatcher(List<Named> matches, boolean alreadyInterned) Factory method for constructing case-sensitivePropertyNameMatcherfor given names.copy()Method for constructing a newJsonFactorythat has the same settings as this instance, but is otherwise independent (i.e. nothing is actually shared, symbol tables are separate).Optional method for constructing parser for non-blocking parsing viaByteArrayFeederinterface (accessed usingJsonParser.nonBlockingInputFeeder()from constructed instance).Optional method for constructing parser for non-blocking parsing viaByteBufferFeederinterface (accessed usingJsonParser.nonBlockingInputFeeder()from constructed instance).Method for accessing custom escapes factory uses forJsonGenerators it creates.Method that returns short textual id identifying format this factory supports.Class<? extends FormatFeature>Method for accessing kind ofFormatFeaturethat a parserJsonParserproduced by this factory would accept, if any;nullreturned if none.Class<? extends FormatFeature>Method for accessing kind ofFormatFeaturethat a parserJsonGeneratorproduced by this factory would accept, if any;nullreturned if none.final booleanChecked whether specified parser feature is enabled.final booleanCheck whether specified generator feature is enabled.protected ObjectMethod that we need to override to actually make restoration go through constructors etc; called by JDK serialization system.rebuild()Method that can be used to create differently configured stream factories: it will create and return a Builder instance with exact settings of this stream factory.snapshot()Method for constructing a newTokenStreamFactorythat has the same settings as this instance, but is otherwise independent (i.e. nothing is actually shared, symbol tables are separate).version()Accessor for getting version of the core package, given a parser instance.Methods inherited from class tools.jackson.core.base.TextualTSFactory
_createContentReference, _createContentReference, _createWriter, canHandleBinaryNatively, canUseCharArrays, createGenerator, createGenerator, createGenerator, createGenerator, createParser, createParser, createParser, createParser, createParser, createParser, createParser, createParserMethods inherited from class tools.jackson.core.base.DecorableTSFactory
_copy, _decorate, _decorate, _decorate, _decorate, _decorate, _decorate, getGeneratorDecorators, getInputDecorator, getOutputDecoratorMethods inherited from class tools.jackson.core.TokenStreamFactory
_checkRangeBoundsForByteArray, _checkRangeBoundsForCharArray, _createContext, _createContext, _createDataOutputWrapper, _fileInputStream, _fileOutputStream, _getBufferRecycler, _getRecyclerPool, _optimizedStreamFromURL, _pathInputStream, _pathOutputStream, _reportRangeError, _unsupported, _unsupported, _wrapIOFailure, createGenerator, createGenerator, createGenerator, createGenerator, createGenerator, createParser, createParser, createParser, createParser, createParser, createParser, createParser, createParser, createParser, createParser, errorReportConfiguration, getFactoryFeatures, getFormatReadFeatures, getFormatWriteFeatures, getStreamReadFeatures, getStreamWriteFeatures, isEnabled, isEnabled, isEnabled, requiresPropertyOrdering, streamReadConstraints, streamWriteConstraints
-
Field Details
-
FORMAT_NAME_JSON
Name used to identify JSON format (and returned bygetFormatName()- See Also:
-
DEFAULT_ROOT_VALUE_SEPARATOR
-
DEFAULT_QUOTE_CHAR
public static final char DEFAULT_QUOTE_CHAR- See Also:
-
_characterEscapes
Definition of custom character escapes to use for generators created by this factory, if any. If null, standard data format specific escapes are used. -
_rootValueSeparator
Separator used between root-level values, if any; null indicates "do not add separator". Default separator is a single space character. -
_maximumNonEscapedChar
protected final int _maximumNonEscapedCharOptional threshold used for automatically escaping character above certain character code value: either0to indicate that no threshold is specified, or value at or above 127 to indicate last character code that is NOT automatically escaped (but depends on other configuration rules for checking). -
_quoteChar
protected final char _quoteCharCharacter used for quoting property names (if property name quoting has not been disabled withJsonWriteFeature.QUOTE_PROPERTY_NAMES) and JSON String values. -
_rootCharSymbols
Each factory comes equipped with a shared root symbol table. It should not be linked back to the original blueprint, to avoid contents from leaking between factories. -
_byteSymbolCanonicalizer
Alternative to the basic symbol table, some stream-based parsers use different name canonicalization method.
-
-
Constructor Details
-
JsonFactory
public JsonFactory()Default constructor used to create factory instances. Creation of a factory instance is a light-weight operation, but it is still a good idea to reuse limited number of factory instances (and quite often just a single instance): factories are used as context for storing some reused processing objects (such as symbol tables parsers use) and this reuse only works within context of a single factory instance. -
JsonFactory
Copy constructor.- Parameters:
src- Original factory to copy configuration from
-
JsonFactory
Constructors used byJsonFactoryBuilderfor instantiation.- Parameters:
b- Builder that has configuration to use- Since:
- 3.0
-
-
Method Details
-
rebuild
Description copied from class:TokenStreamFactoryMethod that can be used to create differently configured stream factories: it will create and return a Builder instance with exact settings of this stream factory.- Specified by:
rebuildin classTokenStreamFactory- Returns:
- Builder instance initialized with configuration this stream factory has
-
builder
Main factory method to use for constructingJsonFactoryinstances with different configuration.- Returns:
- Builder instance to use
-
builderWithJackson2Defaults
Factory method to use for constructingJsonFactoryinstances with different configuration. The builder returned uses default settings more closely matching the default configs used in Jackson 2.x versions.This method is still a work in progress and may not yet fully replicate the default settings of Jackson 2.x.
- Returns:
- Builder instance to use
-
copy
Method for constructing a newJsonFactorythat has the same settings as this instance, but is otherwise independent (i.e. nothing is actually shared, symbol tables are separate).- Specified by:
copyin classTokenStreamFactory- Returns:
- Copy of this factory instance
-
snapshot
Description copied from class:TokenStreamFactoryMethod for constructing a newTokenStreamFactorythat has the same settings as this instance, but is otherwise independent (i.e. nothing is actually shared, symbol tables are separate).Although assumption is that all factories are immutable -- and that we could usually simply return `this` -- method is left unimplemented at this level to make implementors aware of requirement to consider immutability.
- Specified by:
snapshotin interfaceSnapshottable<TokenStreamFactory>- Specified by:
snapshotin classTokenStreamFactory- Returns:
- This factory instance to allow call chaining
-
readResolve
Method that we need to override to actually make restoration go through constructors etc; called by JDK serialization system.- Returns:
- A properly initialized copy of this factory instance
-
version
Accessor for getting version of the core package, given a parser instance. Left for sub-classes to implement.- Specified by:
versionin interfaceVersioned- Specified by:
versionin classTokenStreamFactory- Returns:
- Version of this generator (derived from version declared for
jackson-corejar that contains the class
-
canParseAsync
public boolean canParseAsync()Description copied from class:TokenStreamFactoryIntrospection method that can be used to check whether this factory can create non-blocking parsers: parsers that do not use blocking I/O abstractions but instead use aNonBlockingInputFeeder.- Specified by:
canParseAsyncin classTokenStreamFactory- Returns:
- Whether this factory supports non-blocking ("async") parsing or
not (and consequently whether
createNonBlockingXxx()method(s) work)
-
isEnabled
Checked whether specified parser feature is enabled.- Parameters:
f- Feature to check- Returns:
Trueif feature is enabled;falseotherwise
-
isEnabled
Check whether specified generator feature is enabled.- Parameters:
f- Feature to check- Returns:
Trueif feature is enabled;falseotherwise
-
canUseSchema
Method that can be used to quickly check whether given schema is something that parsers and/or generators constructed by this factory could use. Note that this means possible use, at the level of data format (i.e. schema is for same data format as parsers and generators this factory constructs); individual schema instances may have further usage restrictions.- Specified by:
canUseSchemain classTokenStreamFactory- Parameters:
schema- Schema instance to check- Returns:
- Whether parsers and generators constructed by this factory can use specified format schema instance
-
getFormatName
Method that returns short textual id identifying format this factory supports.Note: sub-classes should override this method; default implementation will return null for all sub-classes
- Specified by:
getFormatNamein classTokenStreamFactory- Returns:
- Name of the format handled by parsers, generators this factory creates
-
getFormatReadFeatureType
Description copied from class:TokenStreamFactoryMethod for accessing kind ofFormatFeaturethat a parserJsonParserproduced by this factory would accept, if any;nullreturned if none.- Overrides:
getFormatReadFeatureTypein classTokenStreamFactory- Returns:
- Type of format-specific stream read features, if any;
nullif none
-
getFormatWriteFeatureType
Description copied from class:TokenStreamFactoryMethod for accessing kind ofFormatFeaturethat a parserJsonGeneratorproduced by this factory would accept, if any;nullreturned if none.- Overrides:
getFormatWriteFeatureTypein classTokenStreamFactory- Returns:
- Type of format-specific stream read features, if any;
nullif none
-
getCharacterEscapes
Method for accessing custom escapes factory uses forJsonGenerators it creates.- Returns:
- CharacterEscapes configured to be used by parser instances
-
getRootValueSeparator
-
createNonBlockingByteArrayParser
Description copied from class:TokenStreamFactoryOptional method for constructing parser for non-blocking parsing viaByteArrayFeederinterface (accessed usingJsonParser.nonBlockingInputFeeder()from constructed instance).If this factory does not support non-blocking parsing (either at all, or from byte array), will throw
UnsupportedOperationException.Note that JSON-backed factory only supports parsing of UTF-8 encoded JSON content (and US-ASCII since it is proper subset); other encodings are not supported at this point.
- Overrides:
createNonBlockingByteArrayParserin classTokenStreamFactory- Parameters:
readCtxt- Object read context to use- Returns:
- Non-blocking parser constructed
-
createNonBlockingByteBufferParser
Description copied from class:TokenStreamFactoryOptional method for constructing parser for non-blocking parsing viaByteBufferFeederinterface (accessed usingJsonParser.nonBlockingInputFeeder()from constructed instance).If this factory does not support non-blocking parsing (either at all, or from byte array), will throw
UnsupportedOperationException.Note that JSON-backed factory only supports parsing of UTF-8 encoded JSON content (and US-ASCII since it is proper subset); other encodings are not supported at this point.
- Overrides:
createNonBlockingByteBufferParserin classTokenStreamFactory- Parameters:
readCtxt- Object read context to use- Returns:
- Non-blocking parser constructed
-
_createNonBlockingContext
-
_createParser
protected JsonParser _createParser(ObjectReadContext readCtxt, IOContext ioCtxt, InputStream in) throws JacksonException - Specified by:
_createParserin classTextualTSFactory- Throws:
JacksonException
-
_createParser
protected JsonParser _createParser(ObjectReadContext readCtxt, IOContext ioCtxt, Reader r) throws JacksonException - Specified by:
_createParserin classTextualTSFactory- Throws:
JacksonException
-
_createParser
protected JsonParser _createParser(ObjectReadContext readCtxt, IOContext ioCtxt, char[] data, int offset, int len, boolean recyclable) throws JacksonException - Specified by:
_createParserin classTextualTSFactory- Throws:
JacksonException
-
_createParser
protected JsonParser _createParser(ObjectReadContext readCtxt, IOContext ioCtxt, byte[] data, int offset, int len) throws JacksonException - Specified by:
_createParserin classTextualTSFactory- Throws:
JacksonException
-
_createParser
protected JsonParser _createParser(ObjectReadContext readCtxt, IOContext ioCtxt, DataInput input) throws JacksonException - Specified by:
_createParserin classTextualTSFactory- Throws:
JacksonException
-
_createGenerator
protected JsonGenerator _createGenerator(ObjectWriteContext writeCtxt, IOContext ioCtxt, Writer out) throws JacksonException Description copied from class:TextualTSFactoryOverridable factory method that actually instantiates generator for givenWriterand context object.This method is specifically designed to remain compatible between minor versions so that sub-classes can count on it being called as expected. That is, it is part of official interface from sub-class perspective, although not a public method available to users of factory implementations.
- Specified by:
_createGeneratorin classTextualTSFactory- Parameters:
writeCtxt- Object write context for generator to useioCtxt- IOContext for generator to useout- Writer for generator to use- Returns:
- Generator constructed
- Throws:
JacksonException- If there is a problem constructing generator
-
_createUTF8Generator
protected JsonGenerator _createUTF8Generator(ObjectWriteContext writeCtxt, IOContext ioCtxt, OutputStream out) throws JacksonException Description copied from class:TextualTSFactoryOverridable factory method that actually instantiates generator for givenOutputStreamand context object, using UTF-8 encoding.This method is specifically designed to remain compatible between minor versions so that sub-classes can count on it being called as expected. That is, it is part of official interface from sub-class perspective, although not a public method available to users of factory implementations.
- Specified by:
_createUTF8Generatorin classTextualTSFactory- Parameters:
writeCtxt- Object write context for generator to useioCtxt- IOContext for generator to useout- OutputStream for generator to use- Returns:
- Generator constructed
- Throws:
JacksonException- If there is a problem constructing generator
-
constructNameMatcher
Description copied from class:TokenStreamFactoryFactory method for constructing case-sensitivePropertyNameMatcherfor given names. It will callString.intern()on names unless specified that this has already been done by caller.- Overrides:
constructNameMatcherin classTokenStreamFactory- Parameters:
matches- Names to match, including both primary names and possible aliasesalreadyInterned- Whether name Strings are alreadyString.intern()edor not- Returns:
- Case-sensitive
PropertyNameMatcherinstance to use
-
constructCINameMatcher
public PropertyNameMatcher constructCINameMatcher(List<Named> matches, boolean alreadyInterned, Locale locale) Description copied from class:TokenStreamFactoryFactory method for constructing case-insensitivePropertyNameMatcherfor given names. It will callString.intern()on names unless specified that this has already been done by caller.- Overrides:
constructCINameMatcherin classTokenStreamFactory- Parameters:
matches- Names to match, including both primary names and possible aliasesalreadyInterned- Whether name Strings are alreadyString.intern()edor notlocale- Locale to use for case-handling- Returns:
- Case-insensitive
PropertyNameMatcherinstance to use
-