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.Versioned
Main 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
Object
but covers following types:InputStream
Reader
byte[]
char[]
String
/CharSequence
URL
File
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
JSON.Feature
Simple on/off (enabled/disabled) features forJSON
; used for simple configuration aspects.
-
Field Summary
Fields Modifier and Type Field Description protected int
_features
protected com.fasterxml.jackson.core.JsonFactory
_jsonFactory
Underlying JSON factory used for creating Streaming parsers and generators.protected com.fasterxml.jackson.core.PrettyPrinter
_prettyPrinter
protected JSONReader
_reader
Blueprint instance of the reader to use for reading JSON as simple Objects.protected com.fasterxml.jackson.core.TreeCodec
_treeCodec
Optional handler forTreeNode
values: if defined, we can read and writeTreeNode
instances that codec supports.protected JSONWriter
_writer
Blueprint instance of the writer to use for writing JSON given simple Objects.static int
CACHE_FLAGS
static JSON
std
Singleton instance with standard, default configuration.
-
Constructor Summary
Constructors Modifier Constructor Description 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)
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.Object
anyFrom(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 (Map
for JSON Objects,List
for JSON Arrays,String
for JSON Strings, null for JSON null,Boolean
for JSON booleans andNumber
for JSON numbers.ValueIterator<java.lang.Object>
anySequenceFrom(java.lang.Object source)
Method for creatingValueIterator
for reading streaming JSON content (specifically line-delimited and concatenated variants); individual values are bound as "Simple" type:Map
,List
,String
,Number
orBoolean
.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.ObjectCodec
asCodec()
Convenience method for constructing an adapter that uses this instance as aObjectCodec
java.lang.String
asString(java.lang.Object value)
<T> T
beanFrom(java.lang.Class<T> type, java.lang.Object source)
<T> ValueIterator<T>
beanSequenceFrom(java.lang.Class<T> type, java.lang.Object source)
Method for creatingValueIterator
for 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.JsonParser
createParser(java.lang.Object source)
Factory method for opening aJsonParser
to read content from one of following supported sourcesInputStream
Reader
byte[]
char[]
String
/CharSequence
URL
File
com.fasterxml.jackson.core.JsonFactory
getStreamingFactory()
com.fasterxml.jackson.core.TreeCodec
getTreeCodec()
boolean
isEnabled(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 aMap
oftype
(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 creatingValueIterator
for 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.Version
version()
JSON
with(com.fasterxml.jackson.core.JsonFactory f)
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).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).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).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).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).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).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).JSON
with(JSON.Feature... features)
Mutant factory for constructing an instance with specified features enabled.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.JSON
without(JSON.Feature... features)
Mutant factory for constructing an instance with specified features disabled.void
write(java.lang.Object value, com.fasterxml.jackson.core.JsonGenerator gen)
void
write(java.lang.Object value, java.io.File f)
void
write(java.lang.Object value, java.io.OutputStream out)
void
write(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 forTreeNode
values: if defined, we can read and writeTreeNode
instances 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:
version
in 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, JSONObjectException
Factory method for opening aJsonParser
to read content from one of following supported sourcesInputStream
Reader
byte[]
char[]
String
/CharSequence
URL
File
Rules regarding closing of the underlying source follow rules that
JsonFactory
has for itscreateParser
method.- Throws:
java.io.IOException
JSONObjectException
- Since:
- 2.10
-
asString
public java.lang.String asString(java.lang.Object value) throws java.io.IOException, JSONObjectException
- Throws:
java.io.IOException
JSONObjectException
-
asBytes
public byte[] asBytes(java.lang.Object value) throws java.io.IOException, JSONObjectException
- Throws:
java.io.IOException
JSONObjectException
-
write
public void write(java.lang.Object value, com.fasterxml.jackson.core.JsonGenerator gen) throws java.io.IOException, JSONObjectException
- Throws:
java.io.IOException
JSONObjectException
-
write
public void write(java.lang.Object value, java.io.OutputStream out) throws java.io.IOException, JSONObjectException
- Throws:
java.io.IOException
JSONObjectException
-
write
public void write(java.lang.Object value, java.io.Writer w) throws java.io.IOException, JSONObjectException
- Throws:
java.io.IOException
JSONObjectException
-
write
public void write(java.lang.Object value, java.io.File f) throws java.io.IOException, JSONObjectException
- Throws:
java.io.IOException
JSONObjectException
-
composeUsing
public JSONComposer<java.io.OutputStream> composeUsing(com.fasterxml.jackson.core.JsonGenerator gen) throws java.io.IOException, JSONObjectException
- Throws:
java.io.IOException
JSONObjectException
-
composeTo
public JSONComposer<java.io.OutputStream> composeTo(java.io.OutputStream out) throws java.io.IOException, JSONObjectException
- Throws:
java.io.IOException
JSONObjectException
-
composeTo
public JSONComposer<java.io.OutputStream> composeTo(java.io.Writer w) throws java.io.IOException, JSONObjectException
- Throws:
java.io.IOException
JSONObjectException
-
composeTo
public JSONComposer<java.io.OutputStream> composeTo(java.io.File f) throws java.io.IOException, JSONObjectException
- Throws:
java.io.IOException
JSONObjectException
-
composeString
public JSONComposer<java.lang.String> composeString() throws java.io.IOException, JSONObjectException
- Throws:
java.io.IOException
JSONObjectException
-
composeBytes
public JSONComposer<byte[]> composeBytes() throws java.io.IOException, JSONObjectException
- Throws:
java.io.IOException
JSONObjectException
-
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.IOException
JSONObjectException
-
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.IOException
JSONObjectException
-
arrayFrom
public java.lang.Object[] arrayFrom(java.lang.Object source) throws java.io.IOException, JSONObjectException
- Throws:
java.io.IOException
JSONObjectException
-
arrayOfFrom
public <T> T[] arrayOfFrom(java.lang.Class<T> type, java.lang.Object source) throws java.io.IOException, JSONObjectException
- Throws:
java.io.IOException
JSONObjectException
-
mapFrom
public java.util.Map<java.lang.String,java.lang.Object> mapFrom(java.lang.Object source) throws java.io.IOException, JSONObjectException
- Throws:
java.io.IOException
JSONObjectException
-
mapOfFrom
public <T> java.util.Map<java.lang.String,T> mapOfFrom(java.lang.Class<T> type, java.lang.Object source) throws java.io.IOException, JSONObjectException
Read method for reading aMap
oftype
(usually POJO) values.- Throws:
java.io.IOException
JSONObjectException
- 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.IOException
JSONObjectException
-
anyFrom
public java.lang.Object anyFrom(java.lang.Object source) throws java.io.IOException
Read method that will take given JSON Source (of one of supported types), read contents and map it to one of simple mappings (Map
for JSON Objects,List
for JSON Arrays,String
for JSON Strings, null for JSON null,Boolean
for JSON booleans andNumber
for JSON numbers.Supported source types include:
InputStream
Reader
File
URL
String
byte[]
char[]
- Throws:
java.io.IOException
-
treeFrom
public <T extends com.fasterxml.jackson.core.TreeNode> T treeFrom(java.lang.Object source) throws java.io.IOException, JSONObjectException
Method for reading content as a JSON Tree (of type that configuredTreeCodec
, seewith(TreeCodec)
) supports.- Throws:
java.io.IOException
JSONObjectException
- 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 creatingValueIterator
for reading streaming JSON content (specifically line-delimited and concatenated variants); individual values are bound to specific Bean (POJO) type.- Throws:
java.io.IOException
JSONObjectException
- Since:
- 2.10
-
anySequenceFrom
public ValueIterator<java.lang.Object> anySequenceFrom(java.lang.Object source) throws java.io.IOException, JSONObjectException
Method for creatingValueIterator
for reading streaming JSON content (specifically line-delimited and concatenated variants); individual values are bound as "Simple" type:Map
,List
,String
,Number
orBoolean
.- Throws:
java.io.IOException
JSONObjectException
- 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 creatingValueIterator
for 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.IOException
JSONObjectException
-
createArrayNode
public <T extends com.fasterxml.jackson.core.TreeNode> T createArrayNode()
Convenience method, equivalent to:getTreeCodec().createArrayNode();
Note that for call to succeed aTreeCodec
must 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 aTreeCodec
must 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.IOException
JSONObjectException
-
_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)
-
-