Package com.fasterxml.jackson.jr.ob
Class JSON
- java.lang.Object
-
- com.fasterxml.jackson.jr.ob.JSON
-
- All Implemented Interfaces:
com.fasterxml.jackson.core.Versioned
public class JSON extends java.lang.Object implements com.fasterxml.jackson.core.VersionedMain entry point for functionality for reading and writing JSON and configuring details of reading and writing.Note that instances are fully immutable, and thereby thread-safe.
Note on source types: source to read is declared as
Objectbut covers following types:InputStreamReaderbyte[]char[]String/CharSequenceURLFile
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classJSON.FeatureSimple on/off (enabled/disabled) features forJSON; used for simple configuration aspects.
-
Field Summary
Fields Modifier and Type Field Description protected int_featuresprotected com.fasterxml.jackson.core.JsonFactory_jsonFactoryUnderlying JSON factory used for creating Streaming parsers and generators.protected com.fasterxml.jackson.core.PrettyPrinter_prettyPrinterprotected JSONReader_readerBlueprint instance of the reader to use for reading JSON as simple Objects.protected com.fasterxml.jackson.core.TreeCodec_treeCodecOptional handler forTreeNodevalues: if defined, we can read and writeTreeNodeinstances that codec supports.protected JSONWriter_writerBlueprint instance of the writer to use for writing JSON given simple Objects.static intCACHE_FLAGSstatic JSONstdSingleton instance with standard, default configuration.
-
Constructor Summary
Constructors Modifier Constructor Description JSON()protectedJSON(int features, com.fasterxml.jackson.core.JsonFactory jsonF, com.fasterxml.jackson.core.TreeCodec trees, JSONReader r, JSONWriter w, com.fasterxml.jackson.core.PrettyPrinter pp)JSON(com.fasterxml.jackson.core.JsonFactory jsonF)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void_close(java.io.Closeable cl)protected void_close(java.io.Closeable cl, java.lang.Exception e)protected <T> T_closeWithError(java.io.Closeable cl, java.lang.Exception e)protected com.fasterxml.jackson.core.JsonGenerator_config(com.fasterxml.jackson.core.JsonGenerator g)protected com.fasterxml.jackson.core.JsonParser_config(com.fasterxml.jackson.core.JsonParser p)protected JSONReader_defaultReader(int features, com.fasterxml.jackson.core.TreeCodec tc, ReaderWriterProvider rwp)protected JSONWriter_defaultWriter(int features, com.fasterxml.jackson.core.TreeCodec tc, ReaderWriterProvider rwp)protected com.fasterxml.jackson.core.JsonParser_initForReading(com.fasterxml.jackson.core.JsonParser p)protected void_noTreeCodec(java.lang.String msg)protected com.fasterxml.jackson.core.JsonParser_parser(java.lang.Object source)protected JSONReader_readerForOperation(com.fasterxml.jackson.core.JsonParser p)protected JSON_with(int features)Internal mutant factory method used for constructingprotected JSON_with(int features, com.fasterxml.jackson.core.JsonFactory jsonF, com.fasterxml.jackson.core.TreeCodec trees, JSONReader reader, JSONWriter writer, com.fasterxml.jackson.core.PrettyPrinter pp)protected void_writeAndClose(java.lang.Object value, com.fasterxml.jackson.core.JsonGenerator g)protected JSONWriter_writerForOperation(com.fasterxml.jackson.core.JsonGenerator gen)java.lang.ObjectanyFrom(java.lang.Object source)Read method that will take given JSON Source (of one of supported types), read contents and map it to one of simple mappings (Mapfor JSON Objects,Listfor JSON Arrays,Stringfor JSON Strings, null for JSON null,Booleanfor JSON booleans andNumberfor JSON numbers.ValueIterator<java.lang.Object>anySequenceFrom(java.lang.Object source)Method for creatingValueIteratorfor reading streaming JSON content (specifically line-delimited and concatenated variants); individual values are bound as "Simple" type:Map,List,String,NumberorBoolean.java.lang.Object[]arrayFrom(java.lang.Object source)<T> T[]arrayOfFrom(java.lang.Class<T> type, java.lang.Object source)byte[]asBytes(java.lang.Object value)com.fasterxml.jackson.core.ObjectCodecasCodec()Convenience method for constructing an adapter that uses this instance as aObjectCodecjava.lang.StringasString(java.lang.Object value)<T> TbeanFrom(java.lang.Class<T> type, java.lang.Object source)<T> ValueIterator<T>beanSequenceFrom(java.lang.Class<T> type, java.lang.Object source)Method for creatingValueIteratorfor reading streaming JSON content (specifically line-delimited and concatenated variants); individual values are bound to specific Bean (POJO) type.JSONComposer<byte[]>composeBytes()<C extends java.util.Collection<java.lang.Object>>
CollectionComposer<?,C>composeCollection(C collection)CollectionComposer<?,java.util.List<java.lang.Object>>composeList()MapComposer<?>composeMap()MapComposer<?>composeMap(java.util.Map<java.lang.String,java.lang.Object> map)JSONComposer<java.lang.String>composeString()JSONComposer<java.io.OutputStream>composeTo(java.io.File f)JSONComposer<java.io.OutputStream>composeTo(java.io.OutputStream out)JSONComposer<java.io.OutputStream>composeTo(java.io.Writer w)JSONComposer<java.io.OutputStream>composeUsing(com.fasterxml.jackson.core.JsonGenerator gen)<T extends com.fasterxml.jackson.core.TreeNode>
TcreateArrayNode()Convenience method, equivalent to:<T extends com.fasterxml.jackson.core.TreeNode>
TcreateObjectNode()Convenience method, equivalent to:com.fasterxml.jackson.core.JsonParsercreateParser(java.lang.Object source)Factory method for opening aJsonParserto read content from one of following supported sourcesInputStreamReaderbyte[]char[]String/CharSequenceURLFilecom.fasterxml.jackson.core.JsonFactorygetStreamingFactory()com.fasterxml.jackson.core.TreeCodecgetTreeCodec()booleanisEnabled(JSON.Feature f)java.util.List<java.lang.Object>listFrom(java.lang.Object source)<T> java.util.List<T>listOfFrom(java.lang.Class<T> type, java.lang.Object source)java.util.Map<java.lang.String,java.lang.Object>mapFrom(java.lang.Object source)<T> java.util.Map<java.lang.String,T>mapOfFrom(java.lang.Class<T> type, java.lang.Object source)Read method for reading aMapoftype(usually POJO) values.<T extends com.fasterxml.jackson.core.TreeNode>
TtreeFrom(java.lang.Object source)Method for reading content as a JSON Tree (of type that configuredTreeCodec, seewith(TreeCodec)) supports.<T extends com.fasterxml.jackson.core.TreeNode>
ValueIterator<T>treeSequenceFrom(java.lang.Object source)Method for creatingValueIteratorfor reading streaming JSON content (specifically line-delimited and concatenated variants); individual values are bound as JSON Trees(of type that configuredTreeCodec, seewith(TreeCodec)) supports.com.fasterxml.jackson.core.Versionversion()JSONwith(com.fasterxml.jackson.core.JsonFactory f)JSONwith(com.fasterxml.jackson.core.PrettyPrinter pp)Mutant factory for constructing an instance with specifiedPrettyPrinter, and returning new instance (or, if there would be no change, this instance).JSONwith(com.fasterxml.jackson.core.TreeCodec c)Mutant factory for constructing an instance with specifiedTreeCodec, and returning new instance (or, if there would be no change, this instance).JSONwith(CollectionBuilder b)Mutant factory for constructing an instance with specifiedCollectionBuilder, and returning new instance (or, if there would be no change, this instance).JSONwith(MapBuilder b)Mutant factory for constructing an instance with specifiedMapBuilder, and returning new instance (or, if there would be no change, this instance).JSONwith(ReaderWriterProvider rwp)Mutant factory for constructing an instance with specifiedReaderWriterProvider, and returning new instance (or, if there would be no change, this instance).JSONwith(JSONReader r)Mutant factory for constructing an instance with specifiedJSONReader, and returning new instance (or, if there would be no change, this instance).JSONwith(JSONWriter w)Mutant factory for constructing an instance with specifiedJSONWriter, and returning new instance (or, if there would be no change, this instance).JSONwith(JSON.Feature... features)Mutant factory for constructing an instance with specified features enabled.JSONwith(JSON.Feature feature, boolean state)Mutant factory for constructing an instance with specified feature enabled or disabled (depending onstate), and returning an instance with that setting; this may either be this instance (if feature already had specified state), or a newly constructed instance.JSONwithout(JSON.Feature... features)Mutant factory for constructing an instance with specified features disabled.voidwrite(java.lang.Object value, com.fasterxml.jackson.core.JsonGenerator gen)voidwrite(java.lang.Object value, java.io.File f)voidwrite(java.lang.Object value, java.io.OutputStream out)voidwrite(java.lang.Object value, java.io.Writer w)
-
-
-
Field Detail
-
CACHE_FLAGS
public static final int CACHE_FLAGS
-
std
public static final JSON std
Singleton instance with standard, default configuration. May be used with direct references like:String json = JSON.std.asString(map);
-
_jsonFactory
protected final com.fasterxml.jackson.core.JsonFactory _jsonFactory
Underlying JSON factory used for creating Streaming parsers and generators.
-
_treeCodec
protected final com.fasterxml.jackson.core.TreeCodec _treeCodec
Optional handler forTreeNodevalues: if defined, we can read and writeTreeNodeinstances that codec supports.
-
_reader
protected final JSONReader _reader
Blueprint instance of the reader to use for reading JSON as simple Objects.
-
_writer
protected final JSONWriter _writer
Blueprint instance of the writer to use for writing JSON given simple Objects.
-
_features
protected final int _features
-
_prettyPrinter
protected final com.fasterxml.jackson.core.PrettyPrinter _prettyPrinter
-
-
Constructor Detail
-
JSON
public JSON()
-
JSON
public JSON(com.fasterxml.jackson.core.JsonFactory jsonF)
-
JSON
protected JSON(int features, com.fasterxml.jackson.core.JsonFactory jsonF, com.fasterxml.jackson.core.TreeCodec trees, JSONReader r, JSONWriter w, com.fasterxml.jackson.core.PrettyPrinter pp)
-
-
Method Detail
-
_defaultReader
protected JSONReader _defaultReader(int features, com.fasterxml.jackson.core.TreeCodec tc, ReaderWriterProvider rwp)
-
_defaultWriter
protected JSONWriter _defaultWriter(int features, com.fasterxml.jackson.core.TreeCodec tc, ReaderWriterProvider rwp)
-
asCodec
public com.fasterxml.jackson.core.ObjectCodec asCodec()
Convenience method for constructing an adapter that uses this instance as aObjectCodec
-
version
public com.fasterxml.jackson.core.Version version()
- Specified by:
versionin interfacecom.fasterxml.jackson.core.Versioned
-
with
public JSON with(com.fasterxml.jackson.core.JsonFactory f)
-
with
public JSON with(com.fasterxml.jackson.core.TreeCodec c)
Mutant factory for constructing an instance with specifiedTreeCodec, and returning new instance (or, if there would be no change, this instance).
-
with
public JSON with(JSONReader r)
Mutant factory for constructing an instance with specifiedJSONReader, and returning new instance (or, if there would be no change, this instance).
-
with
public JSON with(JSONWriter w)
Mutant factory for constructing an instance with specifiedJSONWriter, and returning new instance (or, if there would be no change, this instance).
-
with
public JSON with(com.fasterxml.jackson.core.PrettyPrinter pp)
Mutant factory for constructing an instance with specifiedPrettyPrinter, and returning new instance (or, if there would be no change, this instance).
-
with
public JSON with(MapBuilder b)
Mutant factory for constructing an instance with specifiedMapBuilder, and returning new instance (or, if there would be no change, this instance).
-
with
public JSON with(CollectionBuilder b)
Mutant factory for constructing an instance with specifiedCollectionBuilder, and returning new instance (or, if there would be no change, this instance).
-
with
public JSON with(ReaderWriterProvider rwp)
Mutant factory for constructing an instance with specifiedReaderWriterProvider, and returning new instance (or, if there would be no change, this instance).- Since:
- 2.10
-
with
public JSON with(JSON.Feature feature, boolean state)
Mutant factory for constructing an instance with specified feature enabled or disabled (depending onstate), and returning an instance with that setting; this may either be this instance (if feature already had specified state), or a newly constructed instance.
-
with
public JSON with(JSON.Feature... features)
Mutant factory for constructing an instance with specified features enabled.
-
without
public JSON without(JSON.Feature... features)
Mutant factory for constructing an instance with specified features disabled.
-
_with
protected final JSON _with(int features)
Internal mutant factory method used for constructing
-
_with
protected JSON _with(int features, com.fasterxml.jackson.core.JsonFactory jsonF, com.fasterxml.jackson.core.TreeCodec trees, JSONReader reader, JSONWriter writer, com.fasterxml.jackson.core.PrettyPrinter pp)
-
getTreeCodec
public com.fasterxml.jackson.core.TreeCodec getTreeCodec()
-
getStreamingFactory
public com.fasterxml.jackson.core.JsonFactory getStreamingFactory()
-
isEnabled
public final boolean isEnabled(JSON.Feature f)
-
createParser
public com.fasterxml.jackson.core.JsonParser createParser(java.lang.Object source) throws java.io.IOException, JSONObjectExceptionFactory method for opening aJsonParserto read content from one of following supported sourcesInputStreamReaderbyte[]char[]String/CharSequenceURLFile
Rules regarding closing of the underlying source follow rules that
JsonFactoryhas for itscreateParsermethod.- Throws:
java.io.IOExceptionJSONObjectException- Since:
- 2.10
-
asString
public java.lang.String asString(java.lang.Object value) throws java.io.IOException, JSONObjectException- Throws:
java.io.IOExceptionJSONObjectException
-
asBytes
public byte[] asBytes(java.lang.Object value) throws java.io.IOException, JSONObjectException- Throws:
java.io.IOExceptionJSONObjectException
-
write
public void write(java.lang.Object value, com.fasterxml.jackson.core.JsonGenerator gen) throws java.io.IOException, JSONObjectException- Throws:
java.io.IOExceptionJSONObjectException
-
write
public void write(java.lang.Object value, java.io.OutputStream out) throws java.io.IOException, JSONObjectException- Throws:
java.io.IOExceptionJSONObjectException
-
write
public void write(java.lang.Object value, java.io.Writer w) throws java.io.IOException, JSONObjectException- Throws:
java.io.IOExceptionJSONObjectException
-
write
public void write(java.lang.Object value, java.io.File f) throws java.io.IOException, JSONObjectException- Throws:
java.io.IOExceptionJSONObjectException
-
composeUsing
public JSONComposer<java.io.OutputStream> composeUsing(com.fasterxml.jackson.core.JsonGenerator gen) throws java.io.IOException, JSONObjectException
- Throws:
java.io.IOExceptionJSONObjectException
-
composeTo
public JSONComposer<java.io.OutputStream> composeTo(java.io.OutputStream out) throws java.io.IOException, JSONObjectException
- Throws:
java.io.IOExceptionJSONObjectException
-
composeTo
public JSONComposer<java.io.OutputStream> composeTo(java.io.Writer w) throws java.io.IOException, JSONObjectException
- Throws:
java.io.IOExceptionJSONObjectException
-
composeTo
public JSONComposer<java.io.OutputStream> composeTo(java.io.File f) throws java.io.IOException, JSONObjectException
- Throws:
java.io.IOExceptionJSONObjectException
-
composeString
public JSONComposer<java.lang.String> composeString() throws java.io.IOException, JSONObjectException
- Throws:
java.io.IOExceptionJSONObjectException
-
composeBytes
public JSONComposer<byte[]> composeBytes() throws java.io.IOException, JSONObjectException
- Throws:
java.io.IOExceptionJSONObjectException
-
composeList
public CollectionComposer<?,java.util.List<java.lang.Object>> composeList()
-
composeCollection
public <C extends java.util.Collection<java.lang.Object>> CollectionComposer<?,C> composeCollection(C collection)
-
composeMap
public MapComposer<?> composeMap()
-
composeMap
public MapComposer<?> composeMap(java.util.Map<java.lang.String,java.lang.Object> map)
-
listFrom
public java.util.List<java.lang.Object> listFrom(java.lang.Object source) throws java.io.IOException, JSONObjectException- Throws:
java.io.IOExceptionJSONObjectException
-
listOfFrom
public <T> java.util.List<T> listOfFrom(java.lang.Class<T> type, java.lang.Object source) throws java.io.IOException, JSONObjectException- Throws:
java.io.IOExceptionJSONObjectException
-
arrayFrom
public java.lang.Object[] arrayFrom(java.lang.Object source) throws java.io.IOException, JSONObjectException- Throws:
java.io.IOExceptionJSONObjectException
-
arrayOfFrom
public <T> T[] arrayOfFrom(java.lang.Class<T> type, java.lang.Object source) throws java.io.IOException, JSONObjectException- Throws:
java.io.IOExceptionJSONObjectException
-
mapFrom
public java.util.Map<java.lang.String,java.lang.Object> mapFrom(java.lang.Object source) throws java.io.IOException, JSONObjectException- Throws:
java.io.IOExceptionJSONObjectException
-
mapOfFrom
public <T> java.util.Map<java.lang.String,T> mapOfFrom(java.lang.Class<T> type, java.lang.Object source) throws java.io.IOException, JSONObjectExceptionRead method for reading aMapoftype(usually POJO) values.- Throws:
java.io.IOExceptionJSONObjectException- Since:
- 2.10
-
beanFrom
public <T> T beanFrom(java.lang.Class<T> type, java.lang.Object source) throws java.io.IOException, JSONObjectException- Throws:
java.io.IOExceptionJSONObjectException
-
anyFrom
public java.lang.Object anyFrom(java.lang.Object source) throws java.io.IOExceptionRead method that will take given JSON Source (of one of supported types), read contents and map it to one of simple mappings (Mapfor JSON Objects,Listfor JSON Arrays,Stringfor JSON Strings, null for JSON null,Booleanfor JSON booleans andNumberfor JSON numbers.Supported source types include:
InputStreamReaderFileURLStringbyte[]char[]
- Throws:
java.io.IOException
-
treeFrom
public <T extends com.fasterxml.jackson.core.TreeNode> T treeFrom(java.lang.Object source) throws java.io.IOException, JSONObjectExceptionMethod for reading content as a JSON Tree (of type that configuredTreeCodec, seewith(TreeCodec)) supports.- Throws:
java.io.IOExceptionJSONObjectException- Since:
- 2.8
-
beanSequenceFrom
public <T> ValueIterator<T> beanSequenceFrom(java.lang.Class<T> type, java.lang.Object source) throws java.io.IOException, JSONObjectException
Method for creatingValueIteratorfor reading streaming JSON content (specifically line-delimited and concatenated variants); individual values are bound to specific Bean (POJO) type.- Throws:
java.io.IOExceptionJSONObjectException- Since:
- 2.10
-
anySequenceFrom
public ValueIterator<java.lang.Object> anySequenceFrom(java.lang.Object source) throws java.io.IOException, JSONObjectException
Method for creatingValueIteratorfor reading streaming JSON content (specifically line-delimited and concatenated variants); individual values are bound as "Simple" type:Map,List,String,NumberorBoolean.- Throws:
java.io.IOExceptionJSONObjectException- Since:
- 2.10
-
treeSequenceFrom
public <T extends com.fasterxml.jackson.core.TreeNode> ValueIterator<T> treeSequenceFrom(java.lang.Object source) throws java.io.IOException, JSONObjectException
Method for creatingValueIteratorfor reading streaming JSON content (specifically line-delimited and concatenated variants); individual values are bound as JSON Trees(of type that configuredTreeCodec, seewith(TreeCodec)) supports.- Throws:
java.io.IOExceptionJSONObjectException
-
createArrayNode
public <T extends com.fasterxml.jackson.core.TreeNode> T createArrayNode()
Convenience method, equivalent to:getTreeCodec().createArrayNode();
Note that for call to succeed aTreeCodecmust have been configured with this instance usingwith(TreeCodec)method.- Since:
- 2.8
-
createObjectNode
public <T extends com.fasterxml.jackson.core.TreeNode> T createObjectNode()
Convenience method, equivalent to:getTreeCodec().createObjectNode();
Note that for call to succeed aTreeCodecmust have been configured with this instance usingwith(TreeCodec)method.- Since:
- 2.8
-
_writeAndClose
protected final void _writeAndClose(java.lang.Object value, com.fasterxml.jackson.core.JsonGenerator g) throws java.io.IOException- Throws:
java.io.IOException
-
_writerForOperation
protected JSONWriter _writerForOperation(com.fasterxml.jackson.core.JsonGenerator gen)
-
_readerForOperation
protected JSONReader _readerForOperation(com.fasterxml.jackson.core.JsonParser p)
-
_parser
protected com.fasterxml.jackson.core.JsonParser _parser(java.lang.Object source) throws java.io.IOException, JSONObjectException- Throws:
java.io.IOExceptionJSONObjectException
-
_initForReading
protected com.fasterxml.jackson.core.JsonParser _initForReading(com.fasterxml.jackson.core.JsonParser p) throws java.io.IOException- Throws:
java.io.IOException
-
_config
protected com.fasterxml.jackson.core.JsonGenerator _config(com.fasterxml.jackson.core.JsonGenerator g)
-
_config
protected com.fasterxml.jackson.core.JsonParser _config(com.fasterxml.jackson.core.JsonParser p)
-
_close
protected void _close(java.io.Closeable cl)
-
_close
protected void _close(java.io.Closeable cl, java.lang.Exception e) throws java.io.IOException- Throws:
java.io.IOException
-
_closeWithError
protected <T> T _closeWithError(java.io.Closeable cl, java.lang.Exception e) throws java.io.IOException- Throws:
java.io.IOException- Since:
- 2.8.2
-
_noTreeCodec
protected void _noTreeCodec(java.lang.String msg)
-
-