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 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 isntance of the writer to use for writing JSON given simple Objects.static 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)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)
-
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)ObjectanyFrom(Object source)Object[]arrayFrom(Object source)<T> T[]arrayOfFrom(Class<T> type, Object source)byte[]asBytes(Object value)com.fasterxml.jackson.core.ObjectCodecasCodec()Convenience method for constructing an adapter that uses this instance as aObjectCodecStringasString(Object value)<T> TbeanFrom(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.JsonFactorygetStreamingFactory()com.fasterxml.jackson.core.TreeCodecgetTreeCodec()booleanisEnabled(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.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(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(MapBuilder b)Mutant factory for constructing an instance with specifiedMapBuilder, 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(Object value, com.fasterxml.jackson.core.JsonGenerator gen)voidwrite(Object value, File f)voidwrite(Object value, OutputStream out)voidwrite(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 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 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:
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(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:
IOExceptionJSONObjectException
-
asBytes
public byte[] asBytes(Object value) throws IOException, JSONObjectException
- Throws:
IOExceptionJSONObjectException
-
write
public void write(Object value, com.fasterxml.jackson.core.JsonGenerator gen) throws IOException, JSONObjectException
- Throws:
IOExceptionJSONObjectException
-
write
public void write(Object value, OutputStream out) throws IOException, JSONObjectException
- Throws:
IOExceptionJSONObjectException
-
write
public void write(Object value, Writer w) throws IOException, JSONObjectException
- Throws:
IOExceptionJSONObjectException
-
write
public void write(Object value, File f) throws IOException, JSONObjectException
- Throws:
IOExceptionJSONObjectException
-
composeUsing
public JSONComposer<OutputStream> composeUsing(com.fasterxml.jackson.core.JsonGenerator gen) throws IOException, JSONObjectException
- Throws:
IOExceptionJSONObjectException
-
composeTo
public JSONComposer<OutputStream> composeTo(OutputStream out) throws IOException, JSONObjectException
- Throws:
IOExceptionJSONObjectException
-
composeTo
public JSONComposer<OutputStream> composeTo(Writer w) throws IOException, JSONObjectException
- Throws:
IOExceptionJSONObjectException
-
composeTo
public JSONComposer<OutputStream> composeTo(File f) throws IOException, JSONObjectException
- Throws:
IOExceptionJSONObjectException
-
composeString
public JSONComposer<String> composeString() throws IOException, JSONObjectException
- Throws:
IOExceptionJSONObjectException
-
composeBytes
public JSONComposer<byte[]> composeBytes() throws IOException, JSONObjectException
- Throws:
IOExceptionJSONObjectException
-
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:
IOExceptionJSONObjectException
-
listOfFrom
public <T> List<T> listOfFrom(Class<T> type, Object source) throws IOException, JSONObjectException
- Throws:
IOExceptionJSONObjectException
-
arrayFrom
public Object[] arrayFrom(Object source) throws IOException, JSONObjectException
- Throws:
IOExceptionJSONObjectException
-
arrayOfFrom
public <T> T[] arrayOfFrom(Class<T> type, Object source) throws IOException, JSONObjectException
- Throws:
IOExceptionJSONObjectException
-
mapFrom
public <T> Map<T,Object> mapFrom(Object source) throws IOException, JSONObjectException
- Throws:
IOExceptionJSONObjectException
-
beanFrom
public <T> T beanFrom(Class<T> type, Object source) throws IOException, JSONObjectException
- Throws:
IOExceptionJSONObjectException
-
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 (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:
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:
IOExceptionJSONObjectException- 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 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(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:
IOExceptionJSONObjectException
-
_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)
-
-