|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.codehaus.jackson.JsonFactory
public class JsonFactory
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.
Field Summary | |
---|---|
protected int |
_generatorFeatures
|
protected ObjectCodec |
_objectCodec
Object that implements conversion functionality between Java objects and Json content. |
protected int |
_parserFeatures
|
protected BytesToNameCanonicalizer |
_rootByteSymbols
Alternative to the basic symbol table, some stream-based parsers use different name canonicalization method. |
protected CharsToNameCanonicalizer |
_rootCharSymbols
Each factory comes equipped with a shared root symbol table. |
Constructor Summary | |
---|---|
JsonFactory()
Default constructor used to create factory instances. |
|
JsonFactory(ObjectCodec oc)
|
Method Summary | |
---|---|
protected IOContext |
_createContext(Object srcRef,
boolean resourceManaged)
Overridable construction method that actually instantiates desired generator. |
protected JsonGenerator |
_createJsonGenerator(Writer out,
IOContext ctxt)
Overridable construction method that actually instantiates desired generator |
protected JsonParser |
_createJsonParser(byte[] data,
int offset,
int len,
IOContext ctxt)
|
protected JsonParser |
_createJsonParser(InputStream in,
IOContext ctxt)
Overridable construction method that actually instantiates desired parser. |
protected JsonParser |
_createJsonParser(Reader r,
IOContext ctxt)
|
protected Writer |
_createWriter(OutputStream out,
JsonEncoding enc,
IOContext ctxt)
|
BufferRecycler |
_getBufferRecycler()
Method used by factory to create buffer recycler instances for parsers and generators. |
protected InputStream |
_optimizedStreamFromURL(URL url)
Helper methods used for constructing an optimal stream for parsers to use, when input is to be read from an URL. |
JsonFactory |
configure(JsonGenerator.Feature f,
boolean state)
Method for enabling or disabling specified generator feature (check JsonGenerator.Feature for list of features) |
JsonFactory |
configure(JsonParser.Feature f,
boolean state)
Method for enabling or disabling specified parser feature (check JsonParser.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,
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. |
JsonParser |
createJsonParser(byte[] data)
|
JsonParser |
createJsonParser(byte[] data,
int offset,
int len)
|
JsonParser |
createJsonParser(File f)
Method for constructing json parser instance to parse contents of specified file. |
JsonParser |
createJsonParser(InputStream in)
Method for constructing json parser instance to parse the contents accessed via specified input stream. |
JsonParser |
createJsonParser(Reader r)
Method for constructing json parser instance to parse the contents accessed via specified Reader. |
JsonParser |
createJsonParser(String content)
|
JsonParser |
createJsonParser(URL url)
Method for constructing json parser instance to parse contents of resource reference by given URL. |
JsonFactory |
disable(JsonGenerator.Feature f)
Method for disabling specified generator feature (check JsonGenerator.Feature for list of features) |
JsonFactory |
disable(JsonParser.Feature f)
Method for disabling specified parser features (check JsonParser.Feature for list of features) |
void |
disableGeneratorFeature(JsonGenerator.Feature f)
Deprecated. Use disable(JsonGenerator.Feature) instead |
void |
disableParserFeature(JsonParser.Feature f)
Deprecated. Use disable(JsonParser.Feature) instead |
JsonFactory |
enable(JsonGenerator.Feature f)
Method for enabling specified generator features (check JsonGenerator.Feature for list of features) |
JsonFactory |
enable(JsonParser.Feature f)
Method for enabling specified parser feature (check JsonParser.Feature for list of features) |
void |
enableGeneratorFeature(JsonGenerator.Feature f)
Deprecated. Use enable(JsonGenerator.Feature) instead |
void |
enableParserFeature(JsonParser.Feature f)
Deprecated. Use enable(JsonParser.Feature) instead |
ObjectCodec |
getCodec()
|
boolean |
isEnabled(JsonGenerator.Feature f)
Checked whether specified generator feature is enabled. |
boolean |
isEnabled(JsonParser.Feature f)
Checked whether specified parser feature is enabled. |
boolean |
isGeneratorFeatureEnabled(JsonGenerator.Feature f)
Deprecated. Use isEnabled(JsonGenerator.Feature) instead |
boolean |
isParserFeatureEnabled(JsonParser.Feature f)
Deprecated. Use isEnabled(JsonParser.Feature) instead |
JsonFactory |
setCodec(ObjectCodec oc)
|
void |
setGeneratorFeature(JsonGenerator.Feature f,
boolean state)
Deprecated. Use configure(JsonGenerator.Feature, boolean) instead |
void |
setParserFeature(JsonParser.Feature f,
boolean state)
Deprecated. Use configure(JsonParser.Feature, boolean) instead |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected CharsToNameCanonicalizer _rootCharSymbols
protected BytesToNameCanonicalizer _rootByteSymbols
TODO: should clean up this; looks messy having 2 alternatives with not very clear differences.
protected ObjectCodec _objectCodec
protected int _parserFeatures
protected int _generatorFeatures
Constructor Detail |
---|
public JsonFactory()
public JsonFactory(ObjectCodec oc)
Method Detail |
---|
public final JsonFactory configure(JsonParser.Feature f, boolean state)
JsonParser.Feature
for list of features)
public JsonFactory enable(JsonParser.Feature f)
JsonParser.Feature
for list of features)
public JsonFactory disable(JsonParser.Feature f)
JsonParser.Feature
for list of features)
public final boolean isEnabled(JsonParser.Feature f)
public final void enableParserFeature(JsonParser.Feature f)
enable(JsonParser.Feature)
instead
public final void disableParserFeature(JsonParser.Feature f)
disable(JsonParser.Feature)
instead
public final void setParserFeature(JsonParser.Feature f, boolean state)
configure(JsonParser.Feature, boolean)
instead
public final boolean isParserFeatureEnabled(JsonParser.Feature f)
isEnabled(JsonParser.Feature)
instead
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 final void enableGeneratorFeature(JsonGenerator.Feature f)
enable(JsonGenerator.Feature)
instead
public final void disableGeneratorFeature(JsonGenerator.Feature f)
disable(JsonGenerator.Feature)
instead
public final void setGeneratorFeature(JsonGenerator.Feature f, boolean state)
configure(JsonGenerator.Feature, boolean)
instead
public final boolean isGeneratorFeatureEnabled(JsonGenerator.Feature f)
isEnabled(JsonGenerator.Feature)
instead
public JsonFactory setCodec(ObjectCodec oc)
public ObjectCodec getCodec()
public JsonParser 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 parse
IOException
JsonParseException
public JsonParser 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 parse
IOException
JsonParseException
public JsonParser 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) 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.
in
- InputStream to use for reading JSON content to parse
IOException
JsonParseException
public JsonParser 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) JsonParser.Feature.AUTO_CLOSE_SOURCE
is enabled.
r
- Reader to use for reading JSON content to parse
IOException
JsonParseException
public JsonParser createJsonParser(byte[] data) throws IOException, JsonParseException
IOException
JsonParseException
public JsonParser createJsonParser(byte[] data, int offset, int len) throws IOException, JsonParseException
IOException
JsonParseException
public JsonParser createJsonParser(String content) throws IOException, JsonParseException
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.
out
- OutputStream to use for writing json contentenc
- Character encoding to use
IOException
public 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 content
IOException
public 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 use
IOException
protected IOContext _createContext(Object srcRef, boolean resourceManaged)
protected JsonParser _createJsonParser(InputStream in, IOContext ctxt) throws IOException, JsonParseException
IOException
JsonParseException
protected JsonParser _createJsonParser(Reader r, IOContext ctxt) throws IOException, JsonParseException
IOException
JsonParseException
protected JsonParser _createJsonParser(byte[] data, int offset, int len, IOContext ctxt) throws IOException, JsonParseException
IOException
JsonParseException
protected JsonGenerator _createJsonGenerator(Writer out, IOContext ctxt) throws IOException
IOException
public BufferRecycler _getBufferRecycler()
Note: only public to give access for ObjectMapper
protected InputStream _optimizedStreamFromURL(URL url) throws IOException
IOException
protected Writer _createWriter(OutputStream out, JsonEncoding enc, IOContext ctxt) throws IOException
IOException
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |