Class JsonFactory
- All Implemented Interfaces:
Versioned
,Serializable
JsonParser
)
and
writer (aka generator, JsonGenerator
)
instances.
Factory instances are thread-safe and reusable after configuration (if any). Typically applications and services use only a single globally shared factory instance, unless they need differently configured factories. Factory reuse is important if efficiency matters; most recycling of expensive construct is done on per-factory basis.
Creation of a factory instance is a light-weight operation, and since there is no need for pluggable alternative implementations (as there is no "standard" JSON processor API to implement), the default constructor is used for constructing factory instances.
- Author:
- Tatu Saloranta
- See Also:
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic enum
Enumeration that defines all on/off features that can only be changed forJsonFactory
. -
Field Summary
Modifier and TypeFieldDescriptionprotected final ByteQuadsCanonicalizer
Alternative to the basic symbol table, some stream-based parsers use different name canonicalization method.protected CharacterEscapes
Definition of custom character escapes to use for generators created by this factory, if any.protected ErrorReportConfiguration
Container for configuration values used when handling erroneous token inputs.protected int
Currently enabled factory features.protected final List<JsonGeneratorDecorator>
List ofJsonGeneratorDecorator
s to apply toJsonGenerator
s after construction; applied in the order of addition.protected int
Currently enabled generator features.protected InputDecorator
Optional helper object that may decorate input sources, to do additional processing on input during parsing.protected int
Optional threshold used for automatically escaping character above certain character code value: either0
to 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 ObjectCodec
Object that implements conversion functionality between Java objects and JSON content.protected OutputDecorator
Optional helper object that may decorate output object, to do additional processing on output during content generation.protected int
Currently enabled parser features.protected final char
Character used for quoting field names (if field name quoting has not been disabled withJsonWriteFeature.QUOTE_FIELD_NAMES
) and JSON String values.protected RecyclerPool<BufferRecycler>
protected final CharsToNameCanonicalizer
Each factory comes equipped with a shared root symbol table.protected SerializableString
Separator used between root-level values, if any; null indicates "do not add separator".protected StreamReadConstraints
Read constraints to use forJsonParser
s constructed using this factory.protected StreamWriteConstraints
Write constraints to use forJsonGenerator
s constructed using this factory.protected static final int
Bitfield (set of flags) of all factory features that are enabled by default.protected static final int
Bitfield (set of flags) of all generator features that are enabled by default.protected static final int
Bitfield (set of flags) of all parser features that are enabled by default.static final char
static final SerializableString
static final String
Name used to identify JSON format (and returned bygetFormatName()
-
Constructor Summary
ModifierConstructorDescriptionDefault constructor used to create factory instances.Constructor used byJsonFactoryBuilder
for instantiation.protected
JsonFactory
(JsonFactory src, ObjectCodec codec) Constructor used when copy()ing a factory instance.protected
JsonFactory
(TSFBuilder<?, ?> b, boolean bogus) Constructor for subtypes; needed to work around the fact that before 3.0, this factory has cumbersome dual role as generic type as well as actual implementation for json. -
Method Summary
Modifier and TypeMethodDescriptionprotected void
_checkInvalidCopy
(Class<?> exp) protected static <T> List<T>
protected ContentReference
_createContentReference
(Object contentAccessor) Overridable factory method for constructingContentReference
to pass to parser or generator being created; used in cases where no offset or length is applicable (either irrelevant, or full contents assumed).protected ContentReference
_createContentReference
(Object contentAccessor, int offset, int length) Overridable factory method for constructingContentReference
to pass to parser or generator being created; used in cases where content is available in a static buffer with relevant offset and length (mostly when reading frombyte[]
,char[]
orString
).protected IOContext
_createContext
(ContentReference contentRef, boolean resourceManaged) Overridable factory method that actually instantiates desired context object.protected IOContext
_createContext
(Object rawContentRef, boolean resourceManaged) Deprecated.Since 2.13protected JsonGenerator
_createGenerator
(Writer out, IOContext ctxt) Overridable factory method that actually instantiates generator for givenWriter
and context object.protected IOContext
_createNonBlockingContext
(Object srcRef) Overridable factory method that actually instantiates desired context object for async (non-blocking) parsingprotected JsonParser
_createParser
(byte[] data, int offset, int len, IOContext ctxt) Overridable factory method that actually instantiates parser using givenReader
object for reading content passed as raw byte array.protected JsonParser
_createParser
(char[] data, int offset, int len, IOContext ctxt, boolean recyclable) Overridable factory method that actually instantiates parser using givenchar[]
object for accessing content.protected JsonParser
_createParser
(DataInput input, IOContext ctxt) Optional factory method, expected to be overriddenprotected JsonParser
_createParser
(InputStream in, IOContext ctxt) Overridable factory method that actually instantiates desired parser givenInputStream
and context object.protected JsonParser
_createParser
(Reader r, IOContext ctxt) Overridable factory method that actually instantiates parser using givenReader
object for reading content.protected JsonGenerator
_createUTF8Generator
(OutputStream out, IOContext ctxt) Overridable factory method that actually instantiates generator for givenOutputStream
and context object, using UTF-8 encoding.protected Writer
_createWriter
(OutputStream out, JsonEncoding enc, IOContext ctxt) protected JsonGenerator
Helper method for applying all registeredJsonGeneratorDecorator
s on freshly constructedJsonGenerator
.protected final DataInput
protected final InputStream
_decorate
(InputStream in, IOContext ctxt) protected final OutputStream
_decorate
(OutputStream out, IOContext ctxt) protected final Reader
protected final Writer
Method used by factory to create buffer recycler instances for parsers and generators.Accessor for getting access toRecyclerPool
for gettingBufferRecycler
instance to use.static TSFBuilder<?,
?> builder()
Main factory method to use for constructingJsonFactory
instances with different configuration: creates and returns a builder for collecting configuration settings; instance created by callingbuild()
after all configuration set.boolean
Introspection method that higher-level functionality may call to see whether underlying data format can read and write binary data natively; that is, embeded it as-is without using encodings such as Base64.boolean
Introspection 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
.boolean
Introspection method that can be used by base factory to check whether access usingchar[]
is something that actual parser implementations can take advantage of, over having to useReader
.boolean
canUseSchema
(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.final JsonFactory
configure
(JsonFactory.Feature f, boolean state) Deprecated.since 2.10 useTSFBuilder.configure(JsonFactory.Feature, boolean)
insteadfinal JsonFactory
configure
(JsonGenerator.Feature f, boolean state) Method for enabling or disabling specified generator feature (checkJsonGenerator.Feature
for list of features)final JsonFactory
configure
(JsonParser.Feature f, boolean state) Method for enabling or disabling specified parser feature (checkJsonParser.Feature
for list of features)copy()
Method for constructing a newJsonFactory
that has the same settings as this instance, but is otherwise independent (i.e.Convenience method for constructing generator that uses default encoding of the format (UTF-8 for JSON and most other data formats).createGenerator
(DataOutput out, JsonEncoding enc) Method for constructing generator for writing content using specifiedDataOutput
instance.createGenerator
(File f, JsonEncoding enc) Method for constructing JSON generator for writing JSON content to specified file, overwriting contents it might have (or creating it if such file does not yet exist).Convenience method for constructing generator that uses default encoding of the format (UTF-8 for JSON and most other data formats).createGenerator
(OutputStream out, JsonEncoding enc) Method for constructing JSON generator for writing JSON content using specified output stream.Method for constructing JSON generator for writing JSON content using specified Writer.Deprecated.Since 2.2, usecreateGenerator(OutputStream)
instead.createJsonGenerator
(OutputStream out, JsonEncoding enc) Deprecated.Since 2.2, usecreateGenerator(OutputStream, JsonEncoding)
instead.Deprecated.Since 2.2, usecreateGenerator(Writer)
instead.createJsonParser
(byte[] data) Deprecated.Since 2.2, usecreateParser(byte[])
instead.createJsonParser
(byte[] data, int offset, int len) Deprecated.Since 2.2, usecreateParser(byte[],int,int)
instead.Deprecated.Since 2.2, usecreateParser(File)
instead.Deprecated.Since 2.2, usecreateParser(InputStream)
instead.Deprecated.Since 2.2, usecreateParser(Reader)
instead.createJsonParser
(String content) Deprecated.Since 2.2, usecreateParser(String)
instead.createJsonParser
(URL url) Deprecated.Since 2.2, usecreateParser(URL)
instead.Optional method for constructing parser for non-blocking parsing viaByteArrayFeeder
interface (accessed usingJsonParser.getNonBlockingInputFeeder()
from constructed instance).Optional method for constructing parser for non-blocking parsing viaByteBufferFeeder
interface (accessed usingJsonParser.getNonBlockingInputFeeder()
from constructed instance).createParser
(byte[] data) Method for constructing parser for parsing the contents of given byte array.createParser
(byte[] data, int offset, int len) Method for constructing parser for parsing the contents of given byte array.createParser
(char[] content) Method for constructing parser for parsing contents of given char array.createParser
(char[] content, int offset, int len) Method for constructing parser for parsing contents of given char array.Optional method for constructing parser for reading contents from specifiedDataInput
instance.createParser
(File f) Method for constructing JSON parser instance to parse contents of specified file.Method for constructing JSON parser instance to parse the contents accessed via specified input stream.Method for constructing parser for parsing the contents accessed via specified Reader.createParser
(String content) Method for constructing parser for parsing contents of given String.createParser
(URL url) Method for constructing JSON parser instance to parse contents of resource reference by given URL.Deprecated.since 2.10 useTSFBuilder.configure(JsonFactory.Feature, boolean)
insteadMethod for disabling specified generator feature (checkJsonGenerator.Feature
for list of features)Method for disabling specified parser features (checkJsonParser.Feature
for list of features)Deprecated.since 2.10 useTSFBuilder.configure(JsonFactory.Feature, boolean)
insteadMethod for enabling specified generator features (checkJsonGenerator.Feature
for list of features)Method for enabling specified parser feature (checkJsonParser.Feature
for list of features)Method for accessing custom escapes factory uses forJsonGenerator
s it creates.getCodec()
final int
Method for getting bit set of allJsonFactory.Feature
s enabledint
Method that returns short textual id identifying format this factory supports.int
Class<? extends FormatFeature>
Method for accessing kind ofFormatFeature
that a parserJsonParser
produced by this factory would accept, if any;null
returned if none.Class<? extends FormatFeature>
Method for accessing kind ofFormatFeature
that a parserJsonGenerator
produced by this factory would accept, if any;null
returned if none.final int
Method for getting currently configured input decorator (if any; there is no default decorator).Method for getting currently configured output decorator (if any; there is no default decorator).final int
hasFormat
(InputAccessor acc) protected MatchStrength
final boolean
Checked whether specified parser feature is enabled.final boolean
Check whether specified generator feature is enabled.final boolean
Method for checking if the specified parser feature is enabled.final boolean
Method for checking if the specified stream read feature is enabled.final boolean
Check whether specified stream write feature is enabled.protected Object
Method that we need to override to actually make restoration go through constructors etc: needed to allow JDK serializability of factory instances.TSFBuilder<?,
?> rebuild()
Method that allows construction of differently configured factory, starting with settings of this factory.boolean
Method that can be called to determine if a customObjectCodec
is needed for binding data parsed usingJsonParser
constructed by this factory (which typically also implies the same for serialization withJsonGenerator
).boolean
Introspection method that higher-level functionality may call to see whether underlying data format requires a stable ordering of object properties or not.Method for defining custom escapes factory uses forJsonGenerator
s it creates.setCodec
(ObjectCodec oc) Method for associating aObjectCodec
(typically acom.fasterxml.jackson.databind.ObjectMapper
) with this factory (and more importantly, parsers and generators it constructs).Method for overridingErrorReportConfiguration
defined for this factory.Deprecated.Since 2.10 useTSFBuilder.inputDecorator(InputDecorator)
insteadDeprecated.Since 2.10 useTSFBuilder.outputDecorator(OutputDecorator)
insteadMethod that allows overriding String used for separating root-level JSON values (default is single space character)Method for overridingStreamReadConstraints
defined for this factory.Method for overridingStreamWriteConstraints
defined for this factory.Get the constraints to apply when performing streaming reads.Get the constraints to apply when performing streaming writes.version()
Method called to detect version of the component that implements this interface; returned version should never be null, but may return specific "not available" instance (seeVersion
for details).Methods inherited from class com.fasterxml.jackson.core.TokenStreamFactory
_checkRangeBoundsForByteArray, _checkRangeBoundsForCharArray, _createDataOutputWrapper, _fileInputStream, _fileOutputStream, _optimizedStreamFromURL, _reportRangeError
-
Field Details
-
FORMAT_NAME_JSON
Name used to identify JSON format (and returned bygetFormatName()
- See Also:
-
DEFAULT_FACTORY_FEATURE_FLAGS
protected static final int DEFAULT_FACTORY_FEATURE_FLAGSBitfield (set of flags) of all factory features that are enabled by default. -
DEFAULT_PARSER_FEATURE_FLAGS
protected static final int DEFAULT_PARSER_FEATURE_FLAGSBitfield (set of flags) of all parser features that are enabled by default. -
DEFAULT_GENERATOR_FEATURE_FLAGS
protected static final int DEFAULT_GENERATOR_FEATURE_FLAGSBitfield (set of flags) of all generator features that are enabled by default. -
DEFAULT_ROOT_VALUE_SEPARATOR
-
DEFAULT_QUOTE_CHAR
public static final char DEFAULT_QUOTE_CHAR- Since:
- 2.10
- See Also:
-
_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.- Since:
- 2.6
-
_factoryFeatures
protected int _factoryFeaturesCurrently enabled factory features. -
_parserFeatures
protected int _parserFeaturesCurrently enabled parser features. -
_generatorFeatures
protected int _generatorFeaturesCurrently enabled generator features. -
_recyclerPool
- Since:
- 2.16
-
_objectCodec
Object that implements conversion functionality between Java objects and JSON content. For base JsonFactory implementation usually not set by default, but can be explicitly set. Sub-classes (like @link org.codehaus.jackson.map.MappingJsonFactory} usually provide an implementation. -
_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. -
_streamReadConstraints
Read constraints to use forJsonParser
s constructed using this factory.- Since:
- 2.15
-
_errorReportConfiguration
Container for configuration values used when handling erroneous token inputs.- Since:
- 2.16
-
_streamWriteConstraints
Write constraints to use forJsonGenerator
s constructed using this factory.- Since:
- 2.16
-
_inputDecorator
Optional helper object that may decorate input sources, to do additional processing on input during parsing. -
_outputDecorator
Optional helper object that may decorate output object, to do additional processing on output during content generation. -
_generatorDecorators
List ofJsonGeneratorDecorator
s to apply toJsonGenerator
s after construction; applied in the order of addition.- Since:
- 2.16
-
_rootValueSeparator
Separator used between root-level values, if any; null indicates "do not add separator". Default separator is a single space character.- Since:
- 2.1
-
_maximumNonEscapedChar
protected int _maximumNonEscapedCharOptional threshold used for automatically escaping character above certain character code value: either0
to 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).- Since:
- 2.10
-
_quoteChar
protected final char _quoteCharCharacter used for quoting field names (if field name quoting has not been disabled withJsonWriteFeature.QUOTE_FIELD_NAMES
) and JSON String values.
-
-
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
-
JsonFactory
Constructor used when copy()ing a factory instance.- Parameters:
src
- Original factory to copy settings fromcodec
- Databinding-level codec to use, if any- Since:
- 2.2.1
-
JsonFactory
Constructor used byJsonFactoryBuilder
for instantiation.- Parameters:
b
- Builder that contains settings to use- Since:
- 2.10
-
JsonFactory
Constructor for subtypes; needed to work around the fact that before 3.0, this factory has cumbersome dual role as generic type as well as actual implementation for json.- Parameters:
b
- Builder that contains settings to usebogus
- Argument only needed to separate constructor signature; ignored
-
-
Method Details
-
rebuild
Method that allows construction of differently configured factory, starting with settings of this factory.- Returns:
- Builder instance to use
- Since:
- 2.10
-
builder
Main factory method to use for constructingJsonFactory
instances with different configuration: creates and returns a builder for collecting configuration settings; instance created by callingbuild()
after all configuration set.NOTE: signature unfortunately does not expose true implementation type; this will be fixed in 3.0.
- Returns:
- Builder instance to use
-
copy
Method for constructing a newJsonFactory
that has the same settings as this instance, but is otherwise independent (i.e. nothing is actually shared, symbol tables are separate). Note thatObjectCodec
reference is not copied but is set to null; caller typically needs to set it after calling this method. Reason for this is that the codec is used for callbacks, and assumption is that there is strict 1-to-1 mapping between codec, factory. Caller has to, then, explicitly set codec after making the copy.- Returns:
- Copy of this factory instance
- Since:
- 2.1
-
_checkInvalidCopy
-
_copy
-
readResolve
Method that we need to override to actually make restoration go through constructors etc: needed to allow JDK serializability of factory instances.Note: must be overridden by sub-classes as well.
- Returns:
- Newly constructed instance
-
requiresPropertyOrdering
public boolean requiresPropertyOrdering()Introspection method that higher-level functionality may call to see whether underlying data format requires a stable ordering of object properties or not. This is usually used for determining whether to force a stable ordering (like alphabetic ordering by name) if no ordering if explicitly specified.Default implementation returns
false
as JSON does NOT require stable ordering. Formats that require ordering include positional textual formats likeCSV
, and schema-based binary formats likeAvro
.- Specified by:
requiresPropertyOrdering
in classTokenStreamFactory
- Returns:
- Whether format supported by this factory requires Object properties to be ordered.
- Since:
- 2.3
-
canHandleBinaryNatively
public boolean canHandleBinaryNatively()Introspection method that higher-level functionality may call to see whether underlying data format can read and write binary data natively; that is, embeded it as-is without using encodings such as Base64.Default implementation returns
false
as JSON does not support native access: all binary content must use Base64 encoding. Most binary formats (like Smile and Avro) support native binary content.- Specified by:
canHandleBinaryNatively
in classTokenStreamFactory
- Returns:
- Whether format supported by this factory supports native binary content
- Since:
- 2.3
-
canUseCharArrays
public boolean canUseCharArrays()Introspection method that can be used by base factory to check whether access usingchar[]
is something that actual parser implementations can take advantage of, over having to useReader
. Sub-types are expected to override definition; default implementation (suitable for JSON) alleges that optimization are possible; and thereby is likely to try to accessString
content by first copying it into recyclable intermediate buffer.- Returns:
- Whether access to decoded textual content can be efficiently
accessed using parser method
getTextCharacters()
. - Since:
- 2.4
-
canParseAsync
public boolean canParseAsync()Introspection 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:
canParseAsync
in classTokenStreamFactory
- Returns:
- Whether this factory supports non-blocking ("async") parsing or
not (and consequently whether
createNonBlockingXxx()
method(s) work) - Since:
- 2.9
-
getFormatReadFeatureType
Description copied from class:TokenStreamFactory
Method for accessing kind ofFormatFeature
that a parserJsonParser
produced by this factory would accept, if any;null
returned if none.- Specified by:
getFormatReadFeatureType
in classTokenStreamFactory
- Returns:
- Type of format-specific stream read features, if any;
null
if none
-
getFormatWriteFeatureType
Description copied from class:TokenStreamFactory
Method for accessing kind ofFormatFeature
that a parserJsonGenerator
produced by this factory would accept, if any;null
returned if none.- Specified by:
getFormatWriteFeatureType
in classTokenStreamFactory
- Returns:
- Type of format-specific stream read features, if any;
null
if none
-
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:
canUseSchema
in 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:
getFormatName
in classTokenStreamFactory
- Returns:
- Name of the format handled by parsers, generators this factory creates
-
hasFormat
- Throws:
IOException
-
requiresCustomCodec
public boolean requiresCustomCodec()Method that can be called to determine if a customObjectCodec
is needed for binding data parsed usingJsonParser
constructed by this factory (which typically also implies the same for serialization withJsonGenerator
).- Returns:
- True if custom codec is needed with parsers and
generators created by this factory; false if a general
ObjectCodec
is enough - Since:
- 2.1
-
hasJSONFormat
- Throws:
IOException
-
version
Description copied from interface:Versioned
Method called to detect version of the component that implements this interface; returned version should never be null, but may return specific "not available" instance (seeVersion
for details). -
configure
Deprecated.since 2.10 useTSFBuilder.configure(JsonFactory.Feature, boolean)
insteadMethod for enabling or disabling specified parser feature (checkJsonParser.Feature
for list of features)- Parameters:
f
- Feature to enable/disablestate
- Whether to enable or disable the feature- Returns:
- This factory instance (to allow call chaining)
-
enable
Deprecated.since 2.10 useTSFBuilder.configure(JsonFactory.Feature, boolean)
insteadMethod for enabling specified parser feature (checkJsonFactory.Feature
for list of features)- Parameters:
f
- Feature to enable- Returns:
- This factory instance (to allow call chaining)
-
disable
Deprecated.since 2.10 useTSFBuilder.configure(JsonFactory.Feature, boolean)
insteadMethod for disabling specified parser features (checkJsonFactory.Feature
for list of features)- Parameters:
f
- Feature to disable- Returns:
- This factory instance (to allow call chaining)
-
isEnabled
Checked whether specified parser feature is enabled.- Specified by:
isEnabled
in classTokenStreamFactory
- Parameters:
f
- Feature to check- Returns:
- True if the specified feature is enabled
-
getFactoryFeatures
public final int getFactoryFeatures()Description copied from class:TokenStreamFactory
Method for getting bit set of allJsonFactory.Feature
s enabled- Specified by:
getFactoryFeatures
in classTokenStreamFactory
- Returns:
- Bitset of enabled
JsonFactory.Feature
s.
-
getParserFeatures
public final int getParserFeatures()- Specified by:
getParserFeatures
in classTokenStreamFactory
-
getGeneratorFeatures
public final int getGeneratorFeatures()- Specified by:
getGeneratorFeatures
in classTokenStreamFactory
-
getFormatParserFeatures
public int getFormatParserFeatures()- Specified by:
getFormatParserFeatures
in classTokenStreamFactory
-
getFormatGeneratorFeatures
public int getFormatGeneratorFeatures()- Specified by:
getFormatGeneratorFeatures
in classTokenStreamFactory
-
streamReadConstraints
Description copied from class:TokenStreamFactory
Get the constraints to apply when performing streaming reads.- Specified by:
streamReadConstraints
in classTokenStreamFactory
- Returns:
- Constraints to apply to reads done by
JsonParser
s constructed by this factory.
-
streamWriteConstraints
Description copied from class:TokenStreamFactory
Get the constraints to apply when performing streaming writes.- Specified by:
streamWriteConstraints
in classTokenStreamFactory
- Returns:
- Constraints to apply to reads done by
JsonGenerator
s constructed by this factory.
-
setStreamReadConstraints
Method for overridingStreamReadConstraints
defined for this factory.NOTE: the preferred way to set constraints is by using
TSFBuilder.streamReadConstraints(com.fasterxml.jackson.core.StreamReadConstraints)
: this method is only provided to support older non-builder-based construction. In Jackson 3.x this method will not be available.- Parameters:
src
- Constraints- Returns:
- This factory instance (to allow call chaining)
- Since:
- 2.15
-
setErrorReportConfiguration
Method for overridingErrorReportConfiguration
defined for this factory.NOTE: the preferred way to set constraints is by using
TSFBuilder.errorReportConfiguration(com.fasterxml.jackson.core.ErrorReportConfiguration)
: this method is only provided to support older non-builder-based construction. In Jackson 3.x this method will not be available.- Parameters:
src
- Configuration- Returns:
- This factory instance (to allow call chaining)
- Since:
- 2.16
-
setStreamWriteConstraints
Method for overridingStreamWriteConstraints
defined for this factory.NOTE: the preferred way to set constraints is by using
TSFBuilder.streamWriteConstraints(com.fasterxml.jackson.core.StreamWriteConstraints)
: this method is only provided to support older non-builder-based construction. In Jackson 3.x this method will not be available.- Parameters:
swc
- Constraints- Returns:
- This factory instance (to allow call chaining)
- Since:
- 2.16
-
configure
Method for enabling or disabling specified parser feature (checkJsonParser.Feature
for list of features)- Parameters:
f
- Feature to enable/disablestate
- Whether to enable or disable the feature- Returns:
- This factory instance (to allow call chaining)
-
enable
Method for enabling specified parser feature (checkJsonParser.Feature
for list of features)- Parameters:
f
- Feature to enable- Returns:
- This factory instance (to allow call chaining)
-
disable
Method for disabling specified parser features (checkJsonParser.Feature
for list of features)- Parameters:
f
- Feature to disable- Returns:
- This factory instance (to allow call chaining)
-
isEnabled
Method for checking if the specified parser feature is enabled.- Specified by:
isEnabled
in classTokenStreamFactory
- Parameters:
f
- Feature to check- Returns:
- True if specified feature is enabled
-
isEnabled
Method for checking if the specified stream read feature is enabled.- Specified by:
isEnabled
in classTokenStreamFactory
- Parameters:
f
- Feature to check- Returns:
- True if specified feature is enabled
- Since:
- 2.10
-
getInputDecorator
Method for getting currently configured input decorator (if any; there is no default decorator).- Returns:
- InputDecorator configured, if any
-
setInputDecorator
Deprecated.Since 2.10 useTSFBuilder.inputDecorator(InputDecorator)
insteadMethod for overriding currently configured input decorator- Parameters:
d
- Decorator to configure for this factory, if any (null
if none)- Returns:
- This factory instance (to allow call chaining)
-
configure
Method for enabling or disabling specified generator feature (checkJsonGenerator.Feature
for list of features)- Parameters:
f
- Feature to enable/disablestate
- Whether to enable or disable the feature- Returns:
- This factory instance (to allow call chaining)
-
enable
Method for enabling specified generator features (checkJsonGenerator.Feature
for list of features)- Parameters:
f
- Feature to enable- Returns:
- This factory instance (to allow call chaining)
-
disable
Method for disabling specified generator feature (checkJsonGenerator.Feature
for list of features)- Parameters:
f
- Feature to disable- Returns:
- This factory instance (to allow call chaining)
-
isEnabled
Check whether specified generator feature is enabled.- Specified by:
isEnabled
in classTokenStreamFactory
- Parameters:
f
- Feature to check- Returns:
- Whether specified feature is enabled
-
isEnabled
Check whether specified stream write feature is enabled.- Specified by:
isEnabled
in classTokenStreamFactory
- Parameters:
f
- Feature to check- Returns:
- Whether specified feature is enabled
- Since:
- 2.10
-
getCharacterEscapes
Method for accessing custom escapes factory uses forJsonGenerator
s it creates.- Returns:
- Configured
CharacterEscapes
, if any;null
if none
-
setCharacterEscapes
Method for defining custom escapes factory uses forJsonGenerator
s it creates.- Parameters:
esc
- CharaterEscapes to set (ornull
for "none")- Returns:
- This factory instance (to allow call chaining)
-
getOutputDecorator
Method for getting currently configured output decorator (if any; there is no default decorator).- Returns:
- OutputDecorator configured for generators factory creates, if any;
null
if none.
-
setOutputDecorator
Deprecated.Since 2.10 useTSFBuilder.outputDecorator(OutputDecorator)
insteadMethod for overriding currently configured output decorator- Parameters:
d
- Output decorator to use, if any- Returns:
- This factory instance (to allow call chaining)
-
setRootValueSeparator
Method that allows overriding String used for separating root-level JSON values (default is single space character)- Parameters:
sep
- Separator to use, if any; null means that no separator is automatically added- Returns:
- This factory instance (to allow call chaining)
-
getRootValueSeparator
- Returns:
- Root value separator configured, if any
-
setRecyclerPool
-
setCodec
Method for associating aObjectCodec
(typically acom.fasterxml.jackson.databind.ObjectMapper
) with this factory (and more importantly, parsers and generators it constructs). This is needed to use data-binding methods ofJsonParser
andJsonGenerator
instances.- Parameters:
oc
- Codec to use- Returns:
- This factory instance (to allow call chaining)
-
getCodec
-
createParser
Method for constructing JSON parser instance to parse contents of specified file.Encoding is auto-detected from contents according to JSON specification recommended mechanism. Json specification supports only UTF-8, UTF-16 and UTF-32 as valid encodings, so auto-detection implemented only for this charsets. For other charsets use
createParser(java.io.Reader)
.Underlying input stream (needed for reading contents) will be owned (and managed, i.e. closed as need be) by the parser, since caller has no access to it.
- Specified by:
createParser
in classTokenStreamFactory
- Parameters:
f
- File that contains JSON content to parse- Throws:
IOException
JsonParseException
- Since:
- 2.1
-
createParser
Method for constructing JSON parser instance to parse contents of resource reference by given URL.Encoding is auto-detected from contents according to JSON specification recommended mechanism. Json specification supports only UTF-8, UTF-16 and UTF-32 as valid encodings, so auto-detection implemented only for this charsets. For other charsets use
createParser(java.io.Reader)
.Underlying input stream (needed for reading contents) will be owned (and managed, i.e. closed as need be) by the parser, since caller has no access to it.
- Specified by:
createParser
in classTokenStreamFactory
- Parameters:
url
- URL pointing to resource that contains JSON content to parse- Throws:
IOException
JsonParseException
- Since:
- 2.1
-
createParser
Method for constructing JSON parser instance to parse the contents accessed via specified input stream.The input stream will not be owned by the parser, it will still be managed (i.e. closed if end-of-stream is reacher, or parser close method called) if (and only if)
StreamReadFeature.AUTO_CLOSE_SOURCE
is enabled.Note: no encoding argument is taken since it can always be auto-detected as suggested by JSON RFC. Json specification supports only UTF-8, UTF-16 and UTF-32 as valid encodings, so auto-detection implemented only for this charsets. For other charsets use
createParser(java.io.Reader)
.- Specified by:
createParser
in classTokenStreamFactory
- Parameters:
in
- InputStream to use for reading JSON content to parse- Throws:
IOException
JsonParseException
- Since:
- 2.1
-
createParser
Method for constructing parser for parsing the contents accessed via specified Reader.The read stream will not be owned by the parser, it will still be managed (i.e. closed if end-of-stream is reacher, or parser close method called) if (and only if)
StreamReadFeature.AUTO_CLOSE_SOURCE
is enabled.- Specified by:
createParser
in classTokenStreamFactory
- Parameters:
r
- Reader to use for reading JSON content to parse- Throws:
IOException
JsonParseException
- Since:
- 2.1
-
createParser
Method for constructing parser for parsing the contents of given byte array.- Specified by:
createParser
in classTokenStreamFactory
- Throws:
IOException
JsonParseException
- Since:
- 2.1
-
createParser
public JsonParser createParser(byte[] data, int offset, int len) throws IOException, JsonParseException Method for constructing parser for parsing the contents of given byte array.- Specified by:
createParser
in classTokenStreamFactory
- Parameters:
data
- Buffer that contains data to parseoffset
- Offset of the first data byte within bufferlen
- Length of contents to parse within buffer- Throws:
IOException
JsonParseException
- Since:
- 2.1
-
createParser
Method for constructing parser for parsing contents of given String.- Specified by:
createParser
in classTokenStreamFactory
- Throws:
IOException
JsonParseException
- Since:
- 2.1
-
createParser
Method for constructing parser for parsing contents of given char array.- Specified by:
createParser
in classTokenStreamFactory
- Throws:
IOException
- Since:
- 2.4
-
createParser
Method for constructing parser for parsing contents of given char array.- Specified by:
createParser
in classTokenStreamFactory
- Throws:
IOException
- Since:
- 2.4
-
createParser
Optional method for constructing parser for reading contents from specifiedDataInput
instance.If this factory does not support
DataInput
as source, will throwUnsupportedOperationException
- Specified by:
createParser
in classTokenStreamFactory
- Throws:
IOException
- Since:
- 2.8
-
createNonBlockingByteArrayParser
Optional method for constructing parser for non-blocking parsing viaByteArrayFeeder
interface (accessed usingJsonParser.getNonBlockingInputFeeder()
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.
- Specified by:
createNonBlockingByteArrayParser
in classTokenStreamFactory
- Returns:
- Constructed parser
- Throws:
IOException
- If there are problems constructing parser- Since:
- 2.9
-
createNonBlockingByteBufferParser
Optional method for constructing parser for non-blocking parsing viaByteBufferFeeder
interface (accessed usingJsonParser.getNonBlockingInputFeeder()
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.
- Specified by:
createNonBlockingByteBufferParser
in classTokenStreamFactory
- Returns:
- Constructed parser
- Throws:
IOException
- If there are problems constructing parser- Since:
- 2.14
-
createGenerator
Method for constructing JSON generator for writing JSON content using specified output stream. Encoding to use must be specified, and needs to be one of available types (as per JSON specification).Underlying stream is NOT owned by the generator constructed, so that generator will NOT close the output stream when
JsonGenerator.close()
is called (unless auto-closing feature,JsonGenerator.Feature.AUTO_CLOSE_TARGET
is enabled). Using application needs to close it explicitly if this is the case.Note: there are formats that use fixed encoding (like most binary data formats) and that ignore passed in encoding.
- Specified by:
createGenerator
in classTokenStreamFactory
- Parameters:
out
- OutputStream to use for writing JSON contentenc
- Character encoding to use- Throws:
IOException
- Since:
- 2.1
-
createGenerator
Convenience method for constructing generator that uses default encoding of the format (UTF-8 for JSON and most other data formats).Note: there are formats that use fixed encoding (like most binary data formats).
- Specified by:
createGenerator
in classTokenStreamFactory
- Throws:
IOException
- Since:
- 2.1
-
createGenerator
Method for constructing JSON generator for writing JSON content using specified Writer.Underlying stream is NOT owned by the generator constructed, so that generator will NOT close the Reader when
JsonGenerator.close()
is called (unless auto-closing feature,JsonGenerator.Feature.AUTO_CLOSE_TARGET
is enabled). Using application needs to close it explicitly.- Specified by:
createGenerator
in classTokenStreamFactory
- Parameters:
w
- Writer to use for writing JSON content- Throws:
IOException
- Since:
- 2.1
-
createGenerator
Method for constructing JSON generator for writing JSON content to specified file, overwriting contents it might have (or creating it if such file does not yet exist). Encoding to use must be specified, and needs to be one of available types (as per JSON specification).Underlying stream is owned by the generator constructed, i.e. generator will handle closing of file when
JsonGenerator.close()
is called.- Specified by:
createGenerator
in classTokenStreamFactory
- Parameters:
f
- File to write contents toenc
- Character encoding to use- Throws:
IOException
- Since:
- 2.1
-
createGenerator
Method for constructing generator for writing content using specifiedDataOutput
instance.- Specified by:
createGenerator
in classTokenStreamFactory
- Throws:
IOException
- Since:
- 2.8
-
createGenerator
Convenience method for constructing generator that uses default encoding of the format (UTF-8 for JSON and most other data formats).Note: there are formats that use fixed encoding (like most binary data formats).
- Specified by:
createGenerator
in classTokenStreamFactory
- Throws:
IOException
- Since:
- 2.8
-
createJsonParser
Deprecated.Since 2.2, usecreateParser(File)
instead.Method for constructing JSON parser instance to parse contents of specified file.Encoding is auto-detected from contents according to JSON specification recommended mechanism. Json specification supports only UTF-8, UTF-16 and UTF-32 as valid encodings, so auto-detection implemented only for this charsets. For other charsets use
createParser(java.io.Reader)
.Underlying input stream (needed for reading contents) will be owned (and managed, i.e. closed as need be) by the parser, since caller has no access to it.
- Parameters:
f
- File that contains JSON content to parse- Returns:
- Parser constructed
- Throws:
IOException
- if parser initialization fails due to I/O (read) problemJsonParseException
- if parser initialization fails due to content decoding problem
-
createJsonParser
Deprecated.Since 2.2, usecreateParser(URL)
instead.Method for constructing JSON parser instance to parse contents of resource reference by given URL.Encoding is auto-detected from contents according to JSON specification recommended mechanism. Json specification supports only UTF-8, UTF-16 and UTF-32 as valid encodings, so auto-detection implemented only for this charsets. For other charsets use
createParser(java.io.Reader)
.Underlying input stream (needed for reading contents) will be owned (and managed, i.e. closed as need be) by the parser, since caller has no access to it.
- Parameters:
url
- URL pointing to resource that contains JSON content to parse- Returns:
- Parser constructed
- Throws:
IOException
- if parser initialization fails due to I/O (read) problemJsonParseException
- if parser initialization fails due to content decoding problem
-
createJsonParser
@Deprecated public JsonParser createJsonParser(InputStream in) throws IOException, JsonParseException Deprecated.Since 2.2, usecreateParser(InputStream)
instead.Method for constructing JSON parser instance to parse the contents accessed via specified input stream.The input stream will not be owned by the parser, it will still be managed (i.e. closed if end-of-stream is reacher, or parser close method called) if (and only if)
JsonParser.Feature.AUTO_CLOSE_SOURCE
is enabled.Note: no encoding argument is taken since it can always be auto-detected as suggested by JSON RFC. Json specification supports only UTF-8, UTF-16 and UTF-32 as valid encodings, so auto-detection implemented only for this charsets. For other charsets use
createParser(java.io.Reader)
.- Parameters:
in
- InputStream to use for reading JSON content to parse- Returns:
- Parser constructed
- Throws:
IOException
- if parser initialization fails due to I/O (read) problemJsonParseException
- if parser initialization fails due to content decoding problem
-
createJsonParser
Deprecated.Since 2.2, usecreateParser(Reader)
instead.Method for constructing parser for parsing the contents accessed via specified Reader.The read stream will not be owned by the parser, it will still be managed (i.e. closed if end-of-stream is reacher, or parser close method called) if (and only if)
JsonParser.Feature.AUTO_CLOSE_SOURCE
is enabled.- Parameters:
r
- Reader to use for reading JSON content to parse- Returns:
- Parser constructed
- Throws:
IOException
- if parser initialization fails due to I/O (read) problemJsonParseException
- if parser initialization fails due to content decoding problem
-
createJsonParser
Deprecated.Since 2.2, usecreateParser(byte[])
instead.Method for constructing parser for parsing the contents of given byte array.- Parameters:
data
- Input content to parse- Returns:
- Parser constructed
- Throws:
IOException
- if parser initialization fails due to I/O (read) problemJsonParseException
- if parser initialization fails due to content decoding problem
-
createJsonParser
@Deprecated public JsonParser createJsonParser(byte[] data, int offset, int len) throws IOException, JsonParseException Deprecated.Since 2.2, usecreateParser(byte[],int,int)
instead.Method for constructing parser for parsing the contents of given byte array.- Parameters:
data
- Buffer that contains data to parseoffset
- Offset of the first data byte within bufferlen
- Length of contents to parse within buffer- Returns:
- Parser constructed
- Throws:
IOException
- if parser initialization fails due to I/O (read) problemJsonParseException
- if parser initialization fails due to content decoding problem
-
createJsonParser
@Deprecated public JsonParser createJsonParser(String content) throws IOException, JsonParseException Deprecated.Since 2.2, usecreateParser(String)
instead.Method for constructing parser for parsing contents of given String.- Parameters:
content
- Input content to parse- Returns:
- Parser constructed
- Throws:
IOException
- if parser initialization fails due to I/O (read) problemJsonParseException
- if parser initialization fails due to content decoding problem
-
createJsonGenerator
@Deprecated public JsonGenerator createJsonGenerator(OutputStream out, JsonEncoding enc) throws IOException Deprecated.Since 2.2, usecreateGenerator(OutputStream, JsonEncoding)
instead.Method for constructing JSON generator for writing JSON content using specified output stream. Encoding to use must be specified, and needs to be one of available types (as per JSON specification).Underlying stream is NOT owned by the generator constructed, so that generator will NOT close the output stream when
JsonGenerator.close()
is called (unless auto-closing feature,JsonGenerator.Feature.AUTO_CLOSE_TARGET
is enabled). Using application needs to close it explicitly if this is the case.Note: there are formats that use fixed encoding (like most binary data formats) and that ignore passed in encoding.
- Parameters:
out
- OutputStream to use for writing JSON contentenc
- Character encoding to use- Returns:
- Generator constructed
- Throws:
IOException
- if parser initialization fails due to I/O (write) problem
-
createJsonGenerator
Deprecated.Since 2.2, usecreateGenerator(Writer)
instead.Method for constructing JSON generator for writing JSON content using specified Writer.Underlying stream is NOT owned by the generator constructed, so that generator will NOT close the Reader when
JsonGenerator.close()
is called (unless auto-closing feature,JsonGenerator.Feature.AUTO_CLOSE_TARGET
is enabled). Using application needs to close it explicitly.- Parameters:
out
- Writer to use for writing JSON content- Returns:
- Generator constructed
- Throws:
IOException
- if parser initialization fails due to I/O (write) problem
-
createJsonGenerator
Deprecated.Since 2.2, usecreateGenerator(OutputStream)
instead.Convenience method for constructing generator that uses default encoding of the format (UTF-8 for JSON and most other data formats).Note: there are formats that use fixed encoding (like most binary data formats).
- Parameters:
out
- OutputStream to use for writing JSON content- Returns:
- Generator constructed
- Throws:
IOException
- if parser initialization fails due to I/O (write) problem
-
_createParser
Overridable factory method that actually instantiates desired parser givenInputStream
and 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.
- Parameters:
in
- InputStream to use for reading content to parsectxt
- I/O context to use for parsing- Returns:
- Parser constructed
- Throws:
IOException
- if parser initialization fails due to I/O (read) problem- Since:
- 2.1
-
_createParser
Overridable factory method that actually instantiates parser using givenReader
object for reading content.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.
- Parameters:
r
- Reader to use for reading content to parsectxt
- I/O context to use for parsing- Returns:
- Actual parser to use
- Throws:
IOException
- if parser initialization fails due to I/O (read) problem- Since:
- 2.1
-
_createParser
protected JsonParser _createParser(char[] data, int offset, int len, IOContext ctxt, boolean recyclable) throws IOException Overridable factory method that actually instantiates parser using givenchar[]
object for accessing content.- Parameters:
data
- Buffer that contains content to parseoffset
- Offset to the first character of data to parselen
- Number of characters within buffer to parsectxt
- I/O context to use for parsingrecyclable
- Whether input buffer is recycled by the factory- Returns:
- Actual parser to use
- Throws:
IOException
- if parser initialization fails due to I/O (read) problem- Since:
- 2.4
-
_createParser
protected JsonParser _createParser(byte[] data, int offset, int len, IOContext ctxt) throws IOException Overridable factory method that actually instantiates parser using givenReader
object for reading content passed as raw byte array.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.
- Parameters:
data
- Buffer that contains content to parseoffset
- Offset to the first character of data to parselen
- Number of characters within buffer to parsectxt
- I/O context to use for parsing- Returns:
- Actual parser to use
- Throws:
IOException
- if parser initialization fails due to I/O (read) problem
-
_createParser
Optional factory method, expected to be overridden- Parameters:
input
- DataInput to use for reading content to parsectxt
- I/O context to use for parsing- Returns:
- Actual parser to use
- Throws:
IOException
- if parser initialization fails due to I/O (read) problem- Since:
- 2.8
-
_createGenerator
Overridable factory method that actually instantiates generator for givenWriter
and 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.
- Parameters:
out
- Writer underlying writer to write generated content toctxt
- I/O context to use- Returns:
- This factory instance (to allow call chaining)
- Throws:
IOException
- if parser initialization fails due to I/O (write) problem
-
_createUTF8Generator
Overridable factory method that actually instantiates generator for givenOutputStream
and 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.
- Parameters:
out
- OutputStream underlying writer to write generated content toctxt
- I/O context to use- Returns:
- This factory instance (to allow call chaining)
- Throws:
IOException
- if parser initialization fails due to I/O (write) problem
-
_createWriter
protected Writer _createWriter(OutputStream out, JsonEncoding enc, IOContext ctxt) throws IOException - Throws:
IOException
-
_decorate
- Throws:
IOException
-
_decorate
- Throws:
IOException
-
_decorate
- Throws:
IOException
-
_decorate
- Throws:
IOException
-
_decorate
- Throws:
IOException
-
_decorate
Helper method for applying all registeredJsonGeneratorDecorator
s on freshly constructedJsonGenerator
.- Parameters:
g
- Generator constructed that is to be decorated- Returns:
- Generator after applying all registered
JsonGeneratorDecorator
s. - Since:
- 2.16
-
_getBufferRecycler
Method used by factory to create buffer recycler instances for parsers and generators.Note: only public to give access for
ObjectMapper
- Returns:
- Buffer recycler instance to use
-
_getRecyclerPool
Accessor for getting access toRecyclerPool
for gettingBufferRecycler
instance to use.- Returns:
- RecyclerPool to use.
- Since:
- 2.16
-
_createContext
Overridable factory method that actually instantiates desired context object.- Parameters:
contentRef
- Source/target reference to use for diagnostics, exception messagesresourceManaged
- Whether input/output buffer is managed by this factory or not- Returns:
- I/O context created
-
_createContext
Deprecated.Since 2.13Deprecated variant of_createContext(Object, boolean)
- Parameters:
rawContentRef
- "Raw" source/target referenceresourceManaged
- Whether input/output buffer is managed by this factory or not- Returns:
- I/O context created
-
_createNonBlockingContext
Overridable factory method that actually instantiates desired context object for async (non-blocking) parsing- Parameters:
srcRef
- Source reference to use for diagnostics, exception messages- Returns:
- I/O context created
- Since:
- 2.9.7
-
_createContentReference
Overridable factory method for constructingContentReference
to pass to parser or generator being created; used in cases where no offset or length is applicable (either irrelevant, or full contents assumed).- Parameters:
contentAccessor
- Access to underlying content; depends on source/target, as well as content representation- Returns:
- Reference instance to use
- Since:
- 2.13
-
_createContentReference
Overridable factory method for constructingContentReference
to pass to parser or generator being created; used in cases where content is available in a static buffer with relevant offset and length (mostly when reading frombyte[]
,char[]
orString
).- Parameters:
contentAccessor
- Access to underlying content; depends on source/target, as well as content representationoffset
- Offset of contentlength
- Length of content- Returns:
- Reference instance to use
- Since:
- 2.13
-