Class JsonFactory
- java.lang.Object
-
- com.fasterxml.jackson.core.TokenStreamFactory
-
- com.fasterxml.jackson.core.JsonFactory
-
- All Implemented Interfaces:
Versioned
,java.io.Serializable
- Direct Known Subclasses:
MappingJsonFactory
public class JsonFactory extends TokenStreamFactory implements Versioned, java.io.Serializable
The main factory class of Jackson package, used to configure and construct reader (aka parser,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.
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
JsonFactory.Feature
Enumeration that defines all on/off features that can only be changed forJsonFactory
.
-
Field Summary
Fields Modifier and Type Field Description static char
DEFAULT_QUOTE_CHAR
static SerializableString
DEFAULT_ROOT_VALUE_SEPARATOR
static java.lang.String
FORMAT_NAME_JSON
Name used to identify JSON format (and returned bygetFormatName()
-
Constructor Summary
Constructors Constructor Description JsonFactory()
Default constructor used to create factory instances.JsonFactory(JsonFactoryBuilder b)
Constructor used byJsonFactoryBuilder
for instantiation.JsonFactory(ObjectCodec oc)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description BufferRecycler
_getBufferRecycler()
Method used by factory to create buffer recycler instances for parsers and generators.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
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.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
.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
.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.JsonFactory
configure(JsonFactory.Feature f, boolean state)
Deprecated.since 2.10 useTSFBuilder.configure(JsonFactory.Feature, boolean)
insteadJsonFactory
configure(JsonGenerator.Feature f, boolean state)
Method for enabling or disabling specified generator feature (checkJsonGenerator.Feature
for list of features)JsonFactory
configure(JsonParser.Feature f, boolean state)
Method for enabling or disabling specified parser feature (checkJsonParser.Feature
for list of features)JsonFactory
copy()
Method for constructing a newJsonFactory
that has the same settings as this instance, but is otherwise independent (i.e.JsonGenerator
createGenerator(java.io.DataOutput out)
Convenience method for constructing generator that uses default encoding of the format (UTF-8 for JSON and most other data formats).JsonGenerator
createGenerator(java.io.DataOutput out, JsonEncoding enc)
Method for constructing generator for writing content using specifiedDataOutput
instance.JsonGenerator
createGenerator(java.io.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).JsonGenerator
createGenerator(java.io.OutputStream out)
Convenience method for constructing generator that uses default encoding of the format (UTF-8 for JSON and most other data formats).JsonGenerator
createGenerator(java.io.OutputStream out, JsonEncoding enc)
Method for constructing JSON generator for writing JSON content using specified output stream.JsonGenerator
createGenerator(java.io.Writer w)
Method for constructing JSON generator for writing JSON content using specified Writer.JsonGenerator
createJsonGenerator(java.io.OutputStream out)
Deprecated.Since 2.2, usecreateGenerator(OutputStream)
instead.JsonGenerator
createJsonGenerator(java.io.OutputStream out, JsonEncoding enc)
Deprecated.Since 2.2, usecreateGenerator(OutputStream, JsonEncoding)
instead.JsonGenerator
createJsonGenerator(java.io.Writer out)
Deprecated.Since 2.2, usecreateGenerator(Writer)
instead.JsonParser
createJsonParser(byte[] data)
Deprecated.Since 2.2, usecreateParser(byte[])
instead.JsonParser
createJsonParser(byte[] data, int offset, int len)
Deprecated.Since 2.2, usecreateParser(byte[],int,int)
instead.JsonParser
createJsonParser(java.io.File f)
Deprecated.Since 2.2, usecreateParser(File)
instead.JsonParser
createJsonParser(java.io.InputStream in)
Deprecated.Since 2.2, usecreateParser(InputStream)
instead.JsonParser
createJsonParser(java.io.Reader r)
Deprecated.Since 2.2, usecreateParser(Reader)
instead.JsonParser
createJsonParser(java.lang.String content)
Deprecated.Since 2.2, usecreateParser(String)
instead.JsonParser
createJsonParser(java.net.URL url)
Deprecated.Since 2.2, usecreateParser(URL)
instead.JsonParser
createNonBlockingByteArrayParser()
Optional method for constructing parser for non-blocking parsing viaByteArrayFeeder
interface (accessed usingJsonParser.getNonBlockingInputFeeder()
from constructed instance).JsonParser
createParser(byte[] data)
Method for constructing parser for parsing the contents of given byte array.JsonParser
createParser(byte[] data, int offset, int len)
Method for constructing parser for parsing the contents of given byte array.JsonParser
createParser(char[] content)
Method for constructing parser for parsing contents of given char array.JsonParser
createParser(char[] content, int offset, int len)
Method for constructing parser for parsing contents of given char array.JsonParser
createParser(java.io.DataInput in)
Optional method for constructing parser for reading contents from specifiedDataInput
instance.JsonParser
createParser(java.io.File f)
Method for constructing JSON parser instance to parse contents of specified file.JsonParser
createParser(java.io.InputStream in)
Method for constructing JSON parser instance to parse the contents accessed via specified input stream.JsonParser
createParser(java.io.Reader r)
Method for constructing parser for parsing the contents accessed via specified Reader.JsonParser
createParser(java.lang.String content)
Method for constructing parser for parsing contents of given String.JsonParser
createParser(java.net.URL url)
Method for constructing JSON parser instance to parse contents of resource reference by given URL.JsonFactory
disable(JsonFactory.Feature f)
Deprecated.since 2.10 useTSFBuilder.configure(JsonFactory.Feature, boolean)
insteadJsonFactory
disable(JsonGenerator.Feature f)
Method for disabling specified generator feature (checkJsonGenerator.Feature
for list of features)JsonFactory
disable(JsonParser.Feature f)
Method for disabling specified parser features (checkJsonParser.Feature
for list of features)JsonFactory
enable(JsonFactory.Feature f)
Deprecated.since 2.10 useTSFBuilder.configure(JsonFactory.Feature, boolean)
insteadJsonFactory
enable(JsonGenerator.Feature f)
Method for enabling specified generator features (checkJsonGenerator.Feature
for list of features)JsonFactory
enable(JsonParser.Feature f)
Method for enabling specified parser feature (checkJsonParser.Feature
for list of features)CharacterEscapes
getCharacterEscapes()
Method for accessing custom escapes factory uses forJsonGenerator
s it creates.ObjectCodec
getCodec()
int
getFormatGeneratorFeatures()
java.lang.String
getFormatName()
Method that returns short textual id identifying format this factory supports.int
getFormatParserFeatures()
java.lang.Class<? extends FormatFeature>
getFormatReadFeatureType()
Method for accessing kind ofFormatFeature
that a parserJsonParser
produced by this factory would accept, if any;null
returned if none.java.lang.Class<? extends FormatFeature>
getFormatWriteFeatureType()
Method for accessing kind ofFormatFeature
that a parserJsonGenerator
produced by this factory would accept, if any;null
returned if none.int
getGeneratorFeatures()
InputDecorator
getInputDecorator()
Method for getting currently configured input decorator (if any; there is no default decorator).OutputDecorator
getOutputDecorator()
Method for getting currently configured output decorator (if any; there is no default decorator).int
getParserFeatures()
java.lang.String
getRootValueSeparator()
MatchStrength
hasFormat(InputAccessor acc)
boolean
isEnabled(JsonFactory.Feature f)
Checked whether specified parser feature is enabled.boolean
isEnabled(JsonGenerator.Feature f)
Check whether specified generator feature is enabled.boolean
isEnabled(JsonParser.Feature f)
Method for checking if the specified parser feature is enabled.boolean
isEnabled(StreamReadFeature f)
Method for checking if the specified stream read feature is enabled.boolean
isEnabled(StreamWriteFeature f)
Check whether specified stream write feature is enabled.TSFBuilder<?,?>
rebuild()
Method that allows construction of differently configured factory, starting with settings of this factory.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
).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.JsonFactory
setCharacterEscapes(CharacterEscapes esc)
Method for defining custom escapes factory uses forJsonGenerator
s it creates.JsonFactory
setCodec(ObjectCodec oc)
Method for associating aObjectCodec
(typically acom.fasterxml.jackson.databind.ObjectMapper
) with this factory (and more importantly, parsers and generators it constructs).JsonFactory
setInputDecorator(InputDecorator d)
Deprecated.Since 2.10 useTSFBuilder.inputDecorator(InputDecorator)
insteadJsonFactory
setOutputDecorator(OutputDecorator d)
Deprecated.Since 2.10 useTSFBuilder.outputDecorator(OutputDecorator)
insteadJsonFactory
setRootValueSeparator(java.lang.String sep)
Method that allows overriding String used for separating root-level JSON values (default is single space character)Version
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).
-
-
-
Field Detail
-
FORMAT_NAME_JSON
public static final java.lang.String FORMAT_NAME_JSON
Name used to identify JSON format (and returned bygetFormatName()
- See Also:
- Constant Field Values
-
DEFAULT_ROOT_VALUE_SEPARATOR
public static final SerializableString DEFAULT_ROOT_VALUE_SEPARATOR
-
DEFAULT_QUOTE_CHAR
public static final char DEFAULT_QUOTE_CHAR
- Since:
- 2.10
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
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
public JsonFactory(ObjectCodec oc)
-
JsonFactory
public JsonFactory(JsonFactoryBuilder b)
Constructor used byJsonFactoryBuilder
for instantiation.- Parameters:
b
- Builder that contains settings to use- Since:
- 2.10
-
-
Method Detail
-
rebuild
public TSFBuilder<?,?> rebuild()
Method that allows construction of differently configured factory, starting with settings of this factory.- Returns:
- Builder instance to use
- Since:
- 2.10
-
builder
public 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.NOTE: signature unfortunately does not expose true implementation type; this will be fixed in 3.0.
- Returns:
- Builder instance to use
-
copy
public JsonFactory 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
-
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
public java.lang.Class<? extends FormatFeature> 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
public java.lang.Class<? extends FormatFeature> 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
public 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. 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
public java.lang.String 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
public MatchStrength hasFormat(InputAccessor acc) throws java.io.IOException
- Throws:
java.io.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
-
version
public Version 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 public final JsonFactory configure(JsonFactory.Feature f, boolean state)
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 public JsonFactory enable(JsonFactory.Feature f)
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 public JsonFactory disable(JsonFactory.Feature f)
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
public final boolean isEnabled(JsonFactory.Feature f)
Checked whether specified parser feature is enabled.- Parameters:
f
- Feature to check- Returns:
- True if the specified feature is enabled
-
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
-
configure
public final JsonFactory configure(JsonParser.Feature f, boolean state)
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
public JsonFactory enable(JsonParser.Feature f)
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
public JsonFactory disable(JsonParser.Feature f)
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
public final boolean isEnabled(JsonParser.Feature f)
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
public final boolean isEnabled(StreamReadFeature f)
Method for checking if the specified stream read feature is enabled.- Parameters:
f
- Feature to check- Returns:
- True if specified feature is enabled
- Since:
- 2.10
-
getInputDecorator
public InputDecorator getInputDecorator()
Method for getting currently configured input decorator (if any; there is no default decorator).- Returns:
- InputDecorator configured, if any
-
setInputDecorator
@Deprecated public JsonFactory setInputDecorator(InputDecorator d)
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
public final JsonFactory configure(JsonGenerator.Feature f, boolean state)
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
public JsonFactory enable(JsonGenerator.Feature f)
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
public JsonFactory disable(JsonGenerator.Feature f)
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
public final boolean isEnabled(JsonGenerator.Feature f)
Check whether specified generator feature is enabled.- Specified by:
isEnabled
in classTokenStreamFactory
- Parameters:
f
- Feature to check- Returns:
- Whether specified feature is enabled
-
isEnabled
public final boolean isEnabled(StreamWriteFeature f)
Check whether specified stream write feature is enabled.- Parameters:
f
- Feature to check- Returns:
- Whether specified feature is enabled
- Since:
- 2.10
-
getCharacterEscapes
public CharacterEscapes getCharacterEscapes()
Method for accessing custom escapes factory uses forJsonGenerator
s it creates.- Returns:
- Configured
CharacterEscapes
, if any;null
if none
-
setCharacterEscapes
public JsonFactory setCharacterEscapes(CharacterEscapes esc)
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
public OutputDecorator 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 public JsonFactory setOutputDecorator(OutputDecorator d)
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
public JsonFactory setRootValueSeparator(java.lang.String sep)
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
public java.lang.String getRootValueSeparator()
- Returns:
- Root value separator configured, if any
-
setCodec
public JsonFactory setCodec(ObjectCodec oc)
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
public ObjectCodec getCodec()
-
createParser
public JsonParser createParser(java.io.File f) throws java.io.IOException, JsonParseException
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:
java.io.IOException
JsonParseException
- Since:
- 2.1
-
createParser
public JsonParser createParser(java.net.URL url) throws java.io.IOException, JsonParseException
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:
java.io.IOException
JsonParseException
- Since:
- 2.1
-
createParser
public JsonParser createParser(java.io.InputStream in) throws java.io.IOException, JsonParseException
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:
java.io.IOException
JsonParseException
- Since:
- 2.1
-
createParser
public JsonParser createParser(java.io.Reader r) throws java.io.IOException, JsonParseException
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:
java.io.IOException
JsonParseException
- Since:
- 2.1
-
createParser
public JsonParser createParser(byte[] data) throws java.io.IOException, JsonParseException
Method for constructing parser for parsing the contents of given byte array.- Specified by:
createParser
in classTokenStreamFactory
- Throws:
java.io.IOException
JsonParseException
- Since:
- 2.1
-
createParser
public JsonParser createParser(byte[] data, int offset, int len) throws java.io.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:
java.io.IOException
JsonParseException
- Since:
- 2.1
-
createParser
public JsonParser createParser(java.lang.String content) throws java.io.IOException, JsonParseException
Method for constructing parser for parsing contents of given String.- Specified by:
createParser
in classTokenStreamFactory
- Throws:
java.io.IOException
JsonParseException
- Since:
- 2.1
-
createParser
public JsonParser createParser(char[] content) throws java.io.IOException
Method for constructing parser for parsing contents of given char array.- Specified by:
createParser
in classTokenStreamFactory
- Throws:
java.io.IOException
- Since:
- 2.4
-
createParser
public JsonParser createParser(char[] content, int offset, int len) throws java.io.IOException
Method for constructing parser for parsing contents of given char array.- Specified by:
createParser
in classTokenStreamFactory
- Throws:
java.io.IOException
- Since:
- 2.4
-
createParser
public JsonParser createParser(java.io.DataInput in) throws java.io.IOException
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:
java.io.IOException
- Since:
- 2.8
-
createNonBlockingByteArrayParser
public JsonParser createNonBlockingByteArrayParser() throws java.io.IOException
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
- Throws:
java.io.IOException
- Since:
- 2.9
-
createGenerator
public JsonGenerator createGenerator(java.io.OutputStream out, JsonEncoding enc) throws java.io.IOException
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:
java.io.IOException
- Since:
- 2.1
-
createGenerator
public JsonGenerator createGenerator(java.io.OutputStream out) throws java.io.IOException
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:
java.io.IOException
- Since:
- 2.1
-
createGenerator
public JsonGenerator createGenerator(java.io.Writer w) throws java.io.IOException
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:
java.io.IOException
- Since:
- 2.1
-
createGenerator
public JsonGenerator createGenerator(java.io.File f, JsonEncoding enc) throws java.io.IOException
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:
java.io.IOException
- Since:
- 2.1
-
createGenerator
public JsonGenerator createGenerator(java.io.DataOutput out, JsonEncoding enc) throws java.io.IOException
Method for constructing generator for writing content using specifiedDataOutput
instance.- Specified by:
createGenerator
in classTokenStreamFactory
- Throws:
java.io.IOException
- Since:
- 2.8
-
createGenerator
public JsonGenerator createGenerator(java.io.DataOutput out) throws java.io.IOException
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:
java.io.IOException
- Since:
- 2.8
-
createJsonParser
@Deprecated public JsonParser createJsonParser(java.io.File f) throws java.io.IOException, JsonParseException
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:
java.io.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(java.net.URL url) throws java.io.IOException, JsonParseException
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:
java.io.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(java.io.InputStream in) throws java.io.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:
java.io.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(java.io.Reader r) throws java.io.IOException, JsonParseException
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:
java.io.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) throws java.io.IOException, JsonParseException
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:
java.io.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 java.io.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:
java.io.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(java.lang.String content) throws java.io.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:
java.io.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(java.io.OutputStream out, JsonEncoding enc) throws java.io.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:
java.io.IOException
- if parser initialization fails due to I/O (write) problem
-
createJsonGenerator
@Deprecated public JsonGenerator createJsonGenerator(java.io.Writer out) throws java.io.IOException
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:
java.io.IOException
- if parser initialization fails due to I/O (write) problem
-
createJsonGenerator
@Deprecated public JsonGenerator createJsonGenerator(java.io.OutputStream out) throws java.io.IOException
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:
java.io.IOException
- if parser initialization fails due to I/O (write) problem
-
_getBufferRecycler
public BufferRecycler _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
-
-