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 Object implements com.fasterxml.jackson.core.Versioned
Main entry point for functionality.Note that instances are fully immutable, and thereby thread-safe.
-
-
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 isntance of the writer to use for writing JSON given simple Objects.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)
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 Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
_close(Closeable cl)
protected void
_close(Closeable cl, Exception e)
protected <T> T
_closeWithError(Closeable cl, 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, TypeDetector td)
protected TypeDetector
_defaultTypeDetector(int features)
protected JSONWriter
_defaultWriter(int features, com.fasterxml.jackson.core.TreeCodec tc, TypeDetector td)
protected com.fasterxml.jackson.core.JsonParser
_initForReading(com.fasterxml.jackson.core.JsonParser p)
protected void
_noTreeCodec(String msg)
protected com.fasterxml.jackson.core.JsonParser
_parser(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(Object value, com.fasterxml.jackson.core.JsonGenerator g)
protected JSONWriter
_writerForOperation(com.fasterxml.jackson.core.JsonGenerator gen)
Object
anyFrom(Object source)
Object[]
arrayFrom(Object source)
<T> T[]
arrayOfFrom(Class<T> type, Object source)
byte[]
asBytes(Object value)
com.fasterxml.jackson.core.ObjectCodec
asCodec()
Convenience method for constructing an adapter that uses this instance as aObjectCodec
String
asString(Object value)
<T> T
beanFrom(Class<T> type, Object source)
JSONComposer<byte[]>
composeBytes()
<C extends Collection<Object>>
CollectionComposer<?,C>composeCollection(C collection)
CollectionComposer<?,List<Object>>
composeList()
MapComposer<?>
composeMap()
MapComposer<?>
composeMap(Map<String,Object> map)
JSONComposer<String>
composeString()
JSONComposer<OutputStream>
composeTo(File f)
JSONComposer<OutputStream>
composeTo(OutputStream out)
JSONComposer<OutputStream>
composeTo(Writer w)
JSONComposer<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.JsonFactory
getStreamingFactory()
com.fasterxml.jackson.core.TreeCodec
getTreeCodec()
boolean
isEnabled(JSON.Feature f)
List<Object>
listFrom(Object source)
<T> List<T>
listOfFrom(Class<T> type, Object source)
<T> Map<T,Object>
mapFrom(Object source)
<T extends com.fasterxml.jackson.core.TreeNode>
com.fasterxml.jackson.core.TreeNodetreeFrom(Object source)
Method for reading content as a JSON Tree (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(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(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(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(Object value, com.fasterxml.jackson.core.JsonGenerator gen)
void
write(Object value, File f)
void
write(Object value, OutputStream out)
void
write(Object value, Writer w)
-
-
-
Field Detail
-
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 isntance 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
protected JSON(int features, com.fasterxml.jackson.core.JsonFactory jsonF, com.fasterxml.jackson.core.TreeCodec trees)
-
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
-
_defaultTypeDetector
protected TypeDetector _defaultTypeDetector(int features)
-
_defaultReader
protected JSONReader _defaultReader(int features, com.fasterxml.jackson.core.TreeCodec tc, TypeDetector td)
-
_defaultWriter
protected JSONWriter _defaultWriter(int features, com.fasterxml.jackson.core.TreeCodec tc, TypeDetector td)
-
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(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 final 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)
-
asString
public String asString(Object value) throws IOException, JSONObjectException
- Throws:
IOException
JSONObjectException
-
asBytes
public byte[] asBytes(Object value) throws IOException, JSONObjectException
- Throws:
IOException
JSONObjectException
-
write
public void write(Object value, com.fasterxml.jackson.core.JsonGenerator gen) throws IOException, JSONObjectException
- Throws:
IOException
JSONObjectException
-
write
public void write(Object value, OutputStream out) throws IOException, JSONObjectException
- Throws:
IOException
JSONObjectException
-
write
public void write(Object value, Writer w) throws IOException, JSONObjectException
- Throws:
IOException
JSONObjectException
-
write
public void write(Object value, File f) throws IOException, JSONObjectException
- Throws:
IOException
JSONObjectException
-
composeUsing
public JSONComposer<OutputStream> composeUsing(com.fasterxml.jackson.core.JsonGenerator gen) throws IOException, JSONObjectException
- Throws:
IOException
JSONObjectException
-
composeTo
public JSONComposer<OutputStream> composeTo(OutputStream out) throws IOException, JSONObjectException
- Throws:
IOException
JSONObjectException
-
composeTo
public JSONComposer<OutputStream> composeTo(Writer w) throws IOException, JSONObjectException
- Throws:
IOException
JSONObjectException
-
composeTo
public JSONComposer<OutputStream> composeTo(File f) throws IOException, JSONObjectException
- Throws:
IOException
JSONObjectException
-
composeString
public JSONComposer<String> composeString() throws IOException, JSONObjectException
- Throws:
IOException
JSONObjectException
-
composeBytes
public JSONComposer<byte[]> composeBytes() throws IOException, JSONObjectException
- Throws:
IOException
JSONObjectException
-
composeList
public CollectionComposer<?,List<Object>> composeList()
-
composeCollection
public <C extends Collection<Object>> CollectionComposer<?,C> composeCollection(C collection)
-
composeMap
public MapComposer<?> composeMap()
-
composeMap
public MapComposer<?> composeMap(Map<String,Object> map)
-
listFrom
public List<Object> listFrom(Object source) throws IOException, JSONObjectException
- Throws:
IOException
JSONObjectException
-
listOfFrom
public <T> List<T> listOfFrom(Class<T> type, Object source) throws IOException, JSONObjectException
- Throws:
IOException
JSONObjectException
-
arrayFrom
public Object[] arrayFrom(Object source) throws IOException, JSONObjectException
- Throws:
IOException
JSONObjectException
-
arrayOfFrom
public <T> T[] arrayOfFrom(Class<T> type, Object source) throws IOException, JSONObjectException
- Throws:
IOException
JSONObjectException
-
mapFrom
public <T> Map<T,Object> mapFrom(Object source) throws IOException, JSONObjectException
- Throws:
IOException
JSONObjectException
-
beanFrom
public <T> T beanFrom(Class<T> type, Object source) throws IOException, JSONObjectException
- Throws:
IOException
JSONObjectException
-
anyFrom
public Object anyFrom(Object source) throws 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:
IOException
-
treeFrom
public <T extends com.fasterxml.jackson.core.TreeNode> com.fasterxml.jackson.core.TreeNode treeFrom(Object source) throws IOException, JSONObjectException
Method for reading content as a JSON Tree (of type that configuredTreeCodec
, seewith(TreeCodec)
) supports.- Throws:
IOException
JSONObjectException
- Since:
- 2.8
-
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(Object value, com.fasterxml.jackson.core.JsonGenerator g) throws IOException
- Throws:
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(Object source) throws IOException, JSONObjectException
- Throws:
IOException
JSONObjectException
-
_initForReading
protected com.fasterxml.jackson.core.JsonParser _initForReading(com.fasterxml.jackson.core.JsonParser p) throws IOException
- Throws:
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(Closeable cl)
-
_close
protected void _close(Closeable cl, Exception e) throws IOException
- Throws:
IOException
-
_closeWithError
protected <T> T _closeWithError(Closeable cl, Exception e) throws IOException
- Throws:
IOException
- Since:
- 2.8.2
-
_noTreeCodec
protected void _noTreeCodec(String msg)
-
-