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
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:
InputStreamReaderbyte[]char[]String/CharSequenceURLFile
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classBuilder class that needs to be used for certain kind of "static" configuration (settings that can not vary on per-call basis forJSON), such as Extension registration.static enumSimple on/off (enabled/disabled) features forJSON; used for simple configuration aspects. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final intprotected final com.fasterxml.jackson.core.JsonFactoryUnderlying JSON factory used for creating Streaming parsers and generators.protected final com.fasterxml.jackson.core.PrettyPrinterprotected final JSONReaderBlueprint instance of the reader to use for reading JSON as simple Objects.protected final com.fasterxml.jackson.core.TreeCodecOptional handler forTreeNodevalues: if defined, we can read and writeTreeNodeinstances that codec supports.protected final ValueReaderLocatorprotected final ValueWriterLocatorprotected final JSONWriterBlueprint instance of the writer to use for writing JSON given simple Objects.static final intstatic final JSONSingleton instance with standard, default configuration. -
Constructor Summary
ConstructorsModifierConstructorDescriptionJSON()JSON(com.fasterxml.jackson.core.JsonFactory jsonF) JSON(JSON.Builder b) Constructor used when creating instance usingJSON.Builder.protectedJSON(JSON base, int features, com.fasterxml.jackson.core.JsonFactory jsonF, com.fasterxml.jackson.core.TreeCodec trees, JSONReader r, JSONWriter w, com.fasterxml.jackson.core.PrettyPrinter pp) protectedJSON(JSON base, ValueReaderLocator rloc, ValueWriterLocator wloc) -
Method Summary
Modifier and TypeMethodDescriptionprotected voidprotected <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 JSONReaderprotected JSONWriterprotected com.fasterxml.jackson.core.JsonParser_initForReading(com.fasterxml.jackson.core.JsonParser p) protected void_noTreeCodec(String msg) protected com.fasterxml.jackson.core.JsonParserprotected JSONReader_readerForOperation(com.fasterxml.jackson.core.JsonParser p) protected <T> Tprotected final 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 final void_writeAndClose(Object value, com.fasterxml.jackson.core.JsonGenerator g0) protected JSONWriter_writerForOperation(com.fasterxml.jackson.core.JsonGenerator gen) anySequenceFrom(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.Object[]<T> T[]arrayOfFrom(Class<T> type, Object source) byte[]com.fasterxml.jackson.core.ObjectCodecasCodec()Convenience method for constructing an adapter that uses this instance as aObjectCodec<T> T<T> ValueIterator<T>beanSequenceFrom(Class<T> type, Object source) Method for creatingValueIteratorfor reading streaming JSON content (specifically line-delimited and concatenated variants); individual values are bound to specific Bean (POJO) type.static JSON.Builderbuilder()static JSON.Builderbuilder(com.fasterxml.jackson.core.JsonFactory streamFactory) JSONComposer<byte[]><C extends Collection<Object>>
CollectionComposer<?,C> composeCollection(C collection) MapComposer<?>MapComposer<?>composeMap(Map<String, Object> map) composeTo(OutputStream out) composeUsing(com.fasterxml.jackson.core.JsonGenerator gen) <T extends com.fasterxml.jackson.core.TreeNode>
TConvenience method, equivalent to:<T extends com.fasterxml.jackson.core.TreeNode>
TConvenience method, equivalent to:com.fasterxml.jackson.core.JsonParsercreateParser(Object source) Factory method for opening aJsonParserto read content from one of following supported sourcesInputStreamReaderbyte[]char[]String/CharSequenceURLFilecom.fasterxml.jackson.core.JsonFactorycom.fasterxml.jackson.core.TreeCodecfinal boolean<T> List<T>listOfFrom(Class<T> type, Object source) Read method for reading aMapoftype(usually POJO) values.<T extends com.fasterxml.jackson.core.TreeNode>
TMethod for reading content as a JSON Tree (of type that configuredTreeCodec, seewith(TreeCodec)) supports.<T extends com.fasterxml.jackson.core.TreeNode>
ValueIterator<T>treeSequenceFrom(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()with(com.fasterxml.jackson.core.JsonFactory f) Deprecated.Since 2.11 should not try changing underlying stream factory but create a new instance if necessary: method will be removed from 3.0 at latestwith(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(com.fasterxml.jackson.core.TreeCodec c) Deprecated.Since 2.11 should try using builder (seebuilder()and create properly configured instanceMutant factory for constructing an instance with specifiedCollectionBuilder, and returning new instance (or, if there would be no change, this instance).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(ReaderWriterProvider rwp) Deprecated.Since 2.11 should register usingJacksonJrExtensionwith(JSONReader r) Deprecated.Since 2.11 should try using builder (seebuilder()and create properly configured instancewith(JSONWriter w) Deprecated.Since 2.11 should try using builder (seebuilder()and create properly configured instancewith(JSON.Feature... features) Mutant factory for constructing an instance with specified features enabled.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.without(JSON.Feature... features) Mutant factory for constructing an instance with specified features disabled.voidvoidvoidwrite(Object value, OutputStream out) void
-
Field Details
-
CACHE_FLAGS
public static final int CACHE_FLAGS -
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 _jsonFactoryUnderlying JSON factory used for creating Streaming parsers and generators. -
_treeCodec
protected final com.fasterxml.jackson.core.TreeCodec _treeCodecOptional handler forTreeNodevalues: if defined, we can read and writeTreeNodeinstances that codec supports. -
_valueReaderLocator
-
_valueWriterLocator
-
_reader
Blueprint instance of the reader to use for reading JSON as simple Objects. -
_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 Details
-
JSON
public JSON() -
JSON
public JSON(com.fasterxml.jackson.core.JsonFactory jsonF) -
JSON
Constructor used when creating instance usingJSON.Builder.- Parameters:
b- Builder that has configured settings to use.- Since:
- 2.11
-
JSON
protected JSON(JSON base, 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
-
-
Method Details
-
builder
- Since:
- 2.11
-
builder
- Since:
- 2.11
-
_defaultReader
-
_defaultWriter
-
asCodec
public com.fasterxml.jackson.core.ObjectCodec asCodec()Convenience method for constructing an adapter that uses this instance as aObjectCodec- Returns:
- Wrapper over this object to adapt to
ObjectCodecAPI
-
version
public com.fasterxml.jackson.core.Version version()- Specified by:
versionin interfacecom.fasterxml.jackson.core.Versioned
-
with
Mutant factory for constructing an instance with specifiedPrettyPrinter, and returning new instance (or, if there would be no change, this instance).- Parameters:
pp-PrettyPrinterto use for pretty-printing output (ofnullto disable pretty-printing)- Returns:
- New instance with specified
PrettyPrinter(if not same as currently configured);thisotherwise.
-
with
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
Mutant factory for constructing an instance with specified features enabled. -
without
Mutant factory for constructing an instance with specified features disabled. -
_with
Internal mutant factory method used for constructing -
with
Deprecated.Since 2.11 should not try changing underlying stream factory but create a new instance if necessary: method will be removed from 3.0 at latestMutant factory method for constructing new instance with specifiedJsonFactoryif different from currently configured one (if not, returnthisas-is)- Parameters:
f- Jackson core format factory to use for low-level decoding/encoding- Returns:
- New instance with specified factory (if not same as currently configured);
thisotherwise.
-
with
Deprecated.Since 2.11 should try using builder (seebuilder()and create properly configured instanceMutant factory for constructing an instance with specifiedTreeCodec, and returning new instance (or, if there would be no change, this instance).- Parameters:
c- Tree codec to use for reading/writing of tree representation- Returns:
- New instance with specified codec (if not same as currently configured);
thisotherwise.
-
with
Deprecated.Since 2.11 should try using builder (seebuilder()and create properly configured instanceMutant factory for constructing an instance with specifiedJSONReader, and returning new instance (or, if there would be no change, this instance).- Parameters:
r- CustomizedJSONReaderto use instead of standard one- Returns:
- New instance with specified
JSONReader(if not same as currently configured);thisotherwise.
-
with
Deprecated.Since 2.11 should try using builder (seebuilder()and create properly configured instanceMutant factory for constructing an instance with specifiedJSONWriter, and returning new instance (or, if there would be no change, this instance).- Parameters:
w- CustomizedJSONWriterto use instead of standard one- Returns:
- New instance with specified
JSONWriter(if not same as currently configured);thisotherwise.
-
with
Mutant factory for constructing an instance with specifiedMapBuilder, and returning new instance (or, if there would be no change, this instance). -
with
Mutant factory for constructing an instance with specifiedCollectionBuilder, and returning new instance (or, if there would be no change, this instance). -
with
Deprecated.Since 2.11 should register usingJacksonJrExtensionMutant factory for constructing an instance with specifiedReaderWriterProvider, and returning new instance (or, if there would be no change, this instance). -
_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
-
createParser
public com.fasterxml.jackson.core.JsonParser createParser(Object source) throws IOException, JSONObjectException Factory 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:
IOExceptionJSONObjectException- Since:
- 2.10
-
asString
- Throws:
IOExceptionJSONObjectException
-
asBytes
- Throws:
IOExceptionJSONObjectException
-
write
public void write(Object value, com.fasterxml.jackson.core.JsonGenerator gen) throws IOException, JSONObjectException - Throws:
IOExceptionJSONObjectException
-
write
- Throws:
IOExceptionJSONObjectException
-
write
- Throws:
IOExceptionJSONObjectException
-
write
- 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
- Throws:
IOExceptionJSONObjectException
-
composeTo
- Throws:
IOExceptionJSONObjectException
-
composeString
- Throws:
IOExceptionJSONObjectException
-
composeBytes
- Throws:
IOExceptionJSONObjectException
-
composeList
-
composeCollection
-
composeMap
-
composeMap
-
listFrom
- Throws:
IOExceptionJSONObjectException
-
listOfFrom
- Throws:
IOExceptionJSONObjectException
-
arrayFrom
- Throws:
IOExceptionJSONObjectException
-
arrayOfFrom
- Throws:
IOExceptionJSONObjectException
-
mapFrom
- Throws:
IOExceptionJSONObjectException
-
mapOfFrom
public <T> Map<String,T> mapOfFrom(Class<T> type, Object source) throws IOException, JSONObjectException Read method for reading aMapoftype(usually POJO) values.- Throws:
IOExceptionJSONObjectException- Since:
- 2.10
-
beanFrom
- Throws:
IOExceptionJSONObjectException
-
anyFrom
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> T 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
-
beanSequenceFrom
public <T> ValueIterator<T> beanSequenceFrom(Class<T> type, Object source) throws 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:
IOExceptionJSONObjectException- Since:
- 2.10
-
anySequenceFrom
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:
IOExceptionJSONObjectException- Since:
- 2.10
-
treeSequenceFrom
public <T extends com.fasterxml.jackson.core.TreeNode> ValueIterator<T> treeSequenceFrom(Object source) throws 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:
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(Object value, com.fasterxml.jackson.core.JsonGenerator g0) throws IOException - Throws:
IOException
-
_writerForOperation
-
_readerForOperation
-
_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) -
_closeWithError
- Throws:
IOException
-
_close
-
_throw
- Throws:
IOException
-
_noTreeCodec
-