public class JsonFactory extends Object implements Versioned
JacksonParser) 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.
| 限定符和类型 | 类和说明 |
|---|---|
static class |
JsonFactory.Feature
Enumeration that defines all on/off features that can only be changed for
JsonFactory. |
| 限定符和类型 | 字段和说明 |
|---|---|
static String |
FORMAT_NAME_JSON
Name used to identify JSON format (and returned by
getFormatName() |
| 构造器和说明 |
|---|
JsonFactory()
Default constructor used to create factory instances.
|
JsonFactory(ObjectCodec oc) |
| 限定符和类型 | 方法和说明 |
|---|---|
BufferRecycler |
_getBufferRecycler()
Method used by factory to create buffer recycler instances for parsers
and generators.
|
JsonFactory |
configure(JacksonParser.Feature f,
boolean state)
Method for enabling or disabling specified parser feature (check
JacksonParser.Feature for list of features) |
JsonFactory |
configure(JsonFactory.Feature f,
boolean state)
Method for enabling or disabling specified parser feature (check
JacksonParser.Feature for list of features) |
JsonFactory |
configure(JsonGenerator.Feature f,
boolean state)
Method for enabling or disabling specified generator feature (check
JsonGenerator.Feature for list of features) |
JsonGenerator |
createJsonGenerator(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 |
createJsonGenerator(OutputStream out)
Convenience method for constructing generator that uses default encoding
of the format (UTF-8 for JSON and most other data formats).
|
JsonGenerator |
createJsonGenerator(OutputStream out,
JsonEncoding enc)
Method for constructing JSON generator for writing JSON content using
specified output stream.
|
JsonGenerator |
createJsonGenerator(Writer out)
Method for constructing JSON generator for writing JSON content using
specified Writer.
|
JacksonParser |
createJsonParser(byte[] data)
Method for constructing parser for parsing the contents of given byte
array.
|
JacksonParser |
createJsonParser(byte[] data,
int offset,
int len)
Method for constructing parser for parsing the contents of given byte
array.
|
JacksonParser |
createJsonParser(File f)
Method for constructing JSON parser instance to parse contents of
specified file.
|
JacksonParser |
createJsonParser(InputStream in)
Method for constructing JSON parser instance to parse the contents
accessed via specified input stream.
|
JacksonParser |
createJsonParser(Reader r)
Method for constructing parser for parsing the contents accessed via
specified Reader.
|
JacksonParser |
createJsonParser(String content)
Method for constructing parser for parsing contents of given String.
|
JacksonParser |
createJsonParser(URL url)
Method for constructing JSON parser instance to parse contents of
resource reference by given URL.
|
JsonFactory |
disable(JacksonParser.Feature f)
Method for disabling specified parser features (check
JacksonParser.Feature for list of features) |
JsonFactory |
disable(JsonFactory.Feature f)
Method for disabling specified parser features (check
JsonFactory.Feature for list of features) |
JsonFactory |
disable(JsonGenerator.Feature f)
Method for disabling specified generator feature (check
JsonGenerator.Feature for list of features) |
JsonFactory |
enable(JacksonParser.Feature f)
Method for enabling specified parser feature (check
JacksonParser.Feature for list of features) |
JsonFactory |
enable(JsonFactory.Feature f)
Method for enabling specified parser feature (check
JsonFactory.Feature for list of features) |
JsonFactory |
enable(JsonGenerator.Feature f)
Method for enabling specified generator features (check
JsonGenerator.Feature for list of features) |
CharacterEscapes |
getCharacterEscapes()
Method for accessing custom escapes factory uses for
JsonGenerators it creates. |
ObjectCodec |
getCodec() |
String |
getFormatName()
Method that returns short textual id identifying format this factory
supports.
|
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).
|
MatchStrength |
hasFormat(InputAccessor acc) |
boolean |
isEnabled(JacksonParser.Feature f)
Checked whether specified parser feature is enabled.
|
boolean |
isEnabled(JsonFactory.Feature f)
Checked whether specified parser feature is enabled.
|
boolean |
isEnabled(JsonGenerator.Feature f)
Check whether specified generator feature is enabled.
|
JsonFactory |
setCharacterEscapes(CharacterEscapes esc)
Method for defining custom escapes factory uses for
JsonGenerator
s it creates. |
JsonFactory |
setCodec(ObjectCodec oc)
Method for associating a
ObjectCodec (typically a
com.fasterxml.jackson.databind.ObjectMapper) with this
factory (and more importantly, parsers and generators it constructs). |
JsonFactory |
setInputDecorator(InputDecorator d)
Method for overriding currently configured input decorator
|
JsonFactory |
setOutputDecorator(OutputDecorator d)
Method for overriding currently configured output decorator
|
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 (see
Version for details). |
public static final String FORMAT_NAME_JSON
getFormatName()public JsonFactory()
public JsonFactory(ObjectCodec oc)
public String getFormatName()
Note: sub-classes should override this method; default implementation will return null for all sub-classes
public MatchStrength hasFormat(InputAccessor acc) throws IOException
IOExceptionpublic Version version()
VersionedVersion for details).public final JsonFactory configure(JsonFactory.Feature f, boolean state)
JacksonParser.Feature for list of features)public JsonFactory enable(JsonFactory.Feature f)
JsonFactory.Feature for list of features)public JsonFactory disable(JsonFactory.Feature f)
JsonFactory.Feature for list of features)public final boolean isEnabled(JsonFactory.Feature f)
public final JsonFactory configure(JacksonParser.Feature f, boolean state)
JacksonParser.Feature for list of features)public JsonFactory enable(JacksonParser.Feature f)
JacksonParser.Feature for list of features)public JsonFactory disable(JacksonParser.Feature f)
JacksonParser.Feature for list of features)public final boolean isEnabled(JacksonParser.Feature f)
public InputDecorator getInputDecorator()
public JsonFactory setInputDecorator(InputDecorator d)
public final JsonFactory configure(JsonGenerator.Feature f, boolean state)
JsonGenerator.Feature for list of features)public JsonFactory enable(JsonGenerator.Feature f)
JsonGenerator.Feature for list of features)public JsonFactory disable(JsonGenerator.Feature f)
JsonGenerator.Feature for list of features)public final boolean isEnabled(JsonGenerator.Feature f)
public CharacterEscapes getCharacterEscapes()
JsonGenerators it creates.public JsonFactory setCharacterEscapes(CharacterEscapes esc)
JsonGenerator
s it creates.public OutputDecorator getOutputDecorator()
public JsonFactory setOutputDecorator(OutputDecorator d)
public ObjectCodec getCodec()
public JsonFactory setCodec(ObjectCodec oc)
ObjectCodec (typically a
com.fasterxml.jackson.databind.ObjectMapper) with this
factory (and more importantly, parsers and generators it constructs).
This is needed to use data-binding methods of JacksonParser and
JsonGenerator instances.public JacksonParser createJsonParser(File f) throws IOException, JsonParseException
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.
f - File that contains JSON content to parseIOExceptionJsonParseExceptionpublic JacksonParser createJsonParser(URL url) throws IOException, JsonParseException
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.
url - URL pointing to resource that contains JSON content to parseIOExceptionJsonParseExceptionpublic JacksonParser createJsonParser(InputStream in) throws IOException, JsonParseException
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)
JacksonParser.Feature.AUTO_CLOSE_SOURCE
is enabled.
Note: no encoding argument is taken since it can always be auto-detected as suggested by Json RFC.
in - InputStream to use for reading JSON content to parseIOExceptionJsonParseExceptionpublic JacksonParser createJsonParser(Reader r) throws IOException, JsonParseException
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)
JacksonParser.Feature.AUTO_CLOSE_SOURCE
is enabled.
r - Reader to use for reading JSON content to parseIOExceptionJsonParseExceptionpublic JacksonParser createJsonParser(byte[] data) throws IOException, JsonParseException
public JacksonParser createJsonParser(byte[] data, int offset, int len) throws IOException, JsonParseException
data - Buffer that contains data to parseoffset - Offset of the first data byte within bufferlen - Length of contents to parse within bufferIOExceptionJsonParseExceptionpublic JacksonParser createJsonParser(String content) throws IOException, JsonParseException
public JsonGenerator createJsonGenerator(OutputStream out, JsonEncoding enc) throws IOException
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.
out - OutputStream to use for writing JSON contentenc - Character encoding to useIOExceptionpublic JsonGenerator createJsonGenerator(Writer out) throws IOException
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.
out - Writer to use for writing JSON contentIOExceptionpublic JsonGenerator createJsonGenerator(OutputStream out) throws IOException
Note: there are formats that use fixed encoding (like most binary data formats).
IOExceptionpublic JsonGenerator createJsonGenerator(File f, JsonEncoding enc) throws IOException
Underlying stream is owned by the generator constructed, i.e.
generator will handle closing of file when JsonGenerator.close() is
called.
f - File to write contents toenc - Character encoding to useIOExceptionpublic BufferRecycler _getBufferRecycler()
Note: only public to give access for ObjectMapper
Copyright © 2002–2019 The MyMMSCs Software Foundation. All rights reserved.