public class JSON extends Object implements Versioned
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| Modifier and Type | Class and Description |
|---|---|
static class |
JSON.Builder
Builder class that needs to be used for certain kind of "static" configuration
(settings that can not vary on per-call basis for
JSON), such as
Extension registration. |
static class |
JSON.Feature
Simple on/off (enabled/disabled) features for
JSON; used for simple
configuration aspects. |
| Modifier and Type | Field and Description |
|---|---|
protected int |
_features |
protected JsonFactory |
_jsonFactory
Underlying JSON factory used for creating Streaming parsers and
generators.
|
protected PrettyPrinter |
_prettyPrinter |
protected JSONReader |
_reader
Blueprint instance of the reader to use for reading JSON as simple
Objects.
|
protected TreeCodec |
_treeCodec
|
protected ValueReaderLocator |
_valueReaderLocator |
protected ValueWriterLocator |
_valueWriterLocator |
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.
|
| Modifier | Constructor and Description |
|---|---|
|
JSON() |
|
JSON(JSON.Builder b)
Constructor used when creating instance using
JSON.Builder. |
|
JSON(JsonFactory jsonF) |
protected |
JSON(JSON base,
int features,
JsonFactory jsonF,
TreeCodec trees,
JSONReader r,
JSONWriter w,
PrettyPrinter pp) |
protected |
JSON(JSON base,
ValueReaderLocator rloc,
ValueWriterLocator wloc) |
| Modifier and Type | Method and Description |
|---|---|
protected void |
_close(Closeable cl) |
protected <T> T |
_closeWithError(Closeable cl,
Exception e) |
protected JsonGenerator |
_config(JsonGenerator g) |
protected JsonParser |
_config(JsonParser p) |
protected JSONReader |
_defaultReader() |
protected JSONWriter |
_defaultWriter() |
protected JsonParser |
_initForReading(JsonParser p) |
protected void |
_noTreeCodec(String msg) |
protected JsonParser |
_parser(Object source) |
protected JSONReader |
_readerForOperation(JsonParser p) |
protected <T> T |
_throw(Exception e) |
protected JSON |
_with(int features)
Internal mutant factory method used for constructing
|
protected JSON |
_with(int features,
JsonFactory jsonF,
TreeCodec trees,
JSONReader reader,
JSONWriter writer,
PrettyPrinter pp) |
protected void |
_writeAndClose(Object value,
JsonGenerator g0) |
protected JSONWriter |
_writerForOperation(JsonGenerator gen) |
Object |
anyFrom(Object source)
|
ValueIterator<Object> |
anySequenceFrom(Object source)
Method for creating
ValueIterator for reading
streaming JSON
content (specifically line-delimited and concatenated variants);
individual values are bound as "Simple" type: Map,
List, String, Number or Boolean. |
Object[] |
arrayFrom(Object source) |
<T> T[] |
arrayOfFrom(Class<T> type,
Object source) |
byte[] |
asBytes(Object value) |
ObjectCodec |
asCodec()
Convenience method for constructing an adapter that uses this
instance as a
ObjectCodec |
String |
asString(Object value) |
<T> T |
beanFrom(Class<T> type,
Object source) |
<T> ValueIterator<T> |
beanSequenceFrom(Class<T> type,
Object source)
Method for creating
ValueIterator for reading
streaming JSON
content (specifically line-delimited and concatenated variants);
individual values are bound to specific Bean (POJO) type. |
static JSON.Builder |
builder() |
static JSON.Builder |
builder(JsonFactory streamFactory) |
JSONComposer<byte[]> |
composeBytes() |
<C extends Collection<Object>> |
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(JsonGenerator gen) |
<T extends TreeNode> |
createArrayNode()
Convenience method, equivalent to:
getTreeCodec().createArrayNode();
Note that for call to succeed a
TreeCodec must have been
configured with this instance using with(TreeCodec) method. |
<T extends TreeNode> |
createObjectNode()
Convenience method, equivalent to:
getTreeCodec().createObjectNode();
Note that for call to succeed a
TreeCodec must have been
configured with this instance using with(TreeCodec) method. |
JsonParser |
createParser(Object source)
Factory method for opening a
JsonParser to read content from one of
following supported sources
InputStream
Reader
byte[]
char[]
String/CharSequence
URL
File
Rules regarding closing of the underlying source follow rules
that JsonFactory has for its createParser method. |
JsonFactory |
getStreamingFactory() |
TreeCodec |
getTreeCodec() |
boolean |
isEnabled(JSON.Feature f) |
List<Object> |
listFrom(Object source) |
<T> List<T> |
listOfFrom(Class<T> type,
Object source) |
Map<String,Object> |
mapFrom(Object source) |
<T> Map<String,T> |
mapOfFrom(Class<T> type,
Object source)
Read method for reading a
Map of type (usually POJO) values. |
<T extends TreeNode> |
treeFrom(Object source)
Method for reading content as a JSON Tree (of type that configured
TreeCodec, see with(TreeCodec)) supports. |
<T extends TreeNode> |
treeSequenceFrom(Object source)
Method for creating
ValueIterator for reading
streaming JSON
content (specifically line-delimited and concatenated variants);
individual values are bound as JSON Trees(of type that configured
TreeCodec, see with(TreeCodec)) supports. |
Version |
version() |
JSON |
with(CollectionBuilder b)
Mutant factory for constructing an instance with specified
CollectionBuilder,
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 on
state), 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 |
with(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 latest
|
JSON |
with(JSONReader r)
Deprecated.
Since 2.11 should try using builder (see
builder() and create
properly configured instance |
JSON |
with(JSONWriter w)
Deprecated.
Since 2.11 should try using builder (see
builder() and create
properly configured instance |
JSON |
with(MapBuilder b)
Mutant factory for constructing an instance with specified
MapBuilder,
and returning new instance (or, if there would be no change, this instance). |
JSON |
with(PrettyPrinter pp)
Mutant factory for constructing an instance with specified
PrettyPrinter,
and returning new instance (or, if there would be no change, this instance). |
JSON |
with(ReaderWriterProvider rwp)
Deprecated.
Since 2.11 should register using
JacksonJrExtension |
JSON |
with(TreeCodec c)
Deprecated.
Since 2.11 should try using builder (see
builder() and create
properly configured instance |
JSON |
without(JSON.Feature... features)
Mutant factory for constructing an instance with specified features
disabled.
|
void |
write(Object value,
File f) |
void |
write(Object value,
JsonGenerator gen) |
void |
write(Object value,
OutputStream out) |
void |
write(Object value,
Writer w) |
public static final int CACHE_FLAGS
public static final JSON std
String json = JSON.std.asString(map);
protected final JsonFactory _jsonFactory
protected final TreeCodec _treeCodec
protected final ValueReaderLocator _valueReaderLocator
protected final ValueWriterLocator _valueWriterLocator
protected final JSONReader _reader
protected final JSONWriter _writer
protected final int _features
protected final PrettyPrinter _prettyPrinter
public JSON()
public JSON(JsonFactory jsonF)
public JSON(JSON.Builder b)
JSON.Builder.b - Builder that has configured settings to use.protected JSON(JSON base, int features, JsonFactory jsonF, TreeCodec trees, JSONReader r, JSONWriter w, PrettyPrinter pp)
protected JSON(JSON base, ValueReaderLocator rloc, ValueWriterLocator wloc)
public static JSON.Builder builder()
public static JSON.Builder builder(JsonFactory streamFactory)
protected JSONReader _defaultReader()
protected JSONWriter _defaultWriter()
public ObjectCodec asCodec()
ObjectCodecObjectCodec APIpublic JSON with(PrettyPrinter pp)
PrettyPrinter,
and returning new instance (or, if there would be no change, this instance).pp - PrettyPrinter to use for pretty-printing output (of null to disable
pretty-printing)PrettyPrinter (if not same as currently configured);
this otherwise.public JSON with(JSON.Feature feature, boolean state)
state), and returning
an instance with that setting; this may either be this instance (if feature
already had specified state), or a newly constructed instance.public JSON with(JSON.Feature... features)
public JSON without(JSON.Feature... features)
protected final JSON _with(int features)
@Deprecated public JSON with(JsonFactory f)
JsonFactory
if different from currently configured one (if not, return this as-is)f - Jackson core format factory to use for low-level decoding/encodingthis otherwise.@Deprecated public JSON with(TreeCodec c)
builder() and create
properly configured instanceTreeCodec,
and returning new instance (or, if there would be no change, this instance).c - Tree codec to use for reading/writing of tree representationthis otherwise.@Deprecated public JSON with(JSONReader r)
builder() and create
properly configured instanceJSONReader,
and returning new instance (or, if there would be no change, this instance).r - Customized JSONReader to use instead of standard oneJSONReader (if not same as currently configured);
this otherwise.@Deprecated public JSON with(JSONWriter w)
builder() and create
properly configured instanceJSONWriter,
and returning new instance (or, if there would be no change, this instance).w - Customized JSONWriter to use instead of standard oneJSONWriter (if not same as currently configured);
this otherwise.public JSON with(MapBuilder b)
MapBuilder,
and returning new instance (or, if there would be no change, this instance).public JSON with(CollectionBuilder b)
CollectionBuilder,
and returning new instance (or, if there would be no change, this instance).@Deprecated public JSON with(ReaderWriterProvider rwp)
JacksonJrExtensionReaderWriterProvider,
and returning new instance (or, if there would be no change, this instance).protected JSON _with(int features, JsonFactory jsonF, TreeCodec trees, JSONReader reader, JSONWriter writer, PrettyPrinter pp)
public TreeCodec getTreeCodec()
public JsonFactory getStreamingFactory()
public final boolean isEnabled(JSON.Feature f)
public JsonParser createParser(Object source) throws IOException, JSONObjectException
JsonParser to read content from one of
following supported sources
InputStreamReaderbyte[]char[]String/CharSequenceURLFile
Rules regarding closing of the underlying source follow rules
that JsonFactory has for its createParser method.
IOExceptionJSONObjectExceptionpublic String asString(Object value) throws IOException, JSONObjectException
IOExceptionJSONObjectExceptionpublic byte[] asBytes(Object value) throws IOException, JSONObjectException
IOExceptionJSONObjectExceptionpublic void write(Object value, JsonGenerator gen) throws IOException, JSONObjectException
IOExceptionJSONObjectExceptionpublic void write(Object value, OutputStream out) throws IOException, JSONObjectException
IOExceptionJSONObjectExceptionpublic void write(Object value, Writer w) throws IOException, JSONObjectException
IOExceptionJSONObjectExceptionpublic void write(Object value, File f) throws IOException, JSONObjectException
IOExceptionJSONObjectExceptionpublic JSONComposer<OutputStream> composeUsing(JsonGenerator gen) throws IOException, JSONObjectException
IOExceptionJSONObjectExceptionpublic JSONComposer<OutputStream> composeTo(OutputStream out) throws IOException, JSONObjectException
IOExceptionJSONObjectExceptionpublic JSONComposer<OutputStream> composeTo(Writer w) throws IOException, JSONObjectException
IOExceptionJSONObjectExceptionpublic JSONComposer<OutputStream> composeTo(File f) throws IOException, JSONObjectException
IOExceptionJSONObjectExceptionpublic JSONComposer<String> composeString() throws IOException, JSONObjectException
IOExceptionJSONObjectExceptionpublic JSONComposer<byte[]> composeBytes() throws IOException, JSONObjectException
IOExceptionJSONObjectExceptionpublic CollectionComposer<?,List<Object>> composeList()
public <C extends Collection<Object>> CollectionComposer<?,C> composeCollection(C collection)
public MapComposer<?> composeMap()
public MapComposer<?> composeMap(Map<String,Object> map)
public List<Object> listFrom(Object source) throws IOException, JSONObjectException
IOExceptionJSONObjectExceptionpublic <T> List<T> listOfFrom(Class<T> type, Object source) throws IOException, JSONObjectException
IOExceptionJSONObjectExceptionpublic Object[] arrayFrom(Object source) throws IOException, JSONObjectException
IOExceptionJSONObjectExceptionpublic <T> T[] arrayOfFrom(Class<T> type, Object source) throws IOException, JSONObjectException
IOExceptionJSONObjectExceptionpublic Map<String,Object> mapFrom(Object source) throws IOException, JSONObjectException
IOExceptionJSONObjectExceptionpublic <T> Map<String,T> mapOfFrom(Class<T> type, Object source) throws IOException, JSONObjectException
Map of type (usually POJO) values.IOExceptionJSONObjectExceptionpublic <T> T beanFrom(Class<T> type, Object source) throws IOException, JSONObjectException
IOExceptionJSONObjectExceptionpublic Object anyFrom(Object source) throws IOException
Map
for JSON Objects, List for JSON Arrays, String
for JSON Strings, null for JSON null, Boolean for JSON booleans
and Number for JSON numbers.
Supported source types include:
InputStreamReaderFileURLStringbyte[]char[]IOExceptionpublic <T extends TreeNode> T treeFrom(Object source) throws IOException, JSONObjectException
TreeCodec, see with(TreeCodec)) supports.IOExceptionJSONObjectExceptionpublic <T> ValueIterator<T> beanSequenceFrom(Class<T> type, Object source) throws IOException, JSONObjectException
ValueIterator for reading
streaming JSON
content (specifically line-delimited and concatenated variants);
individual values are bound to specific Bean (POJO) type.IOExceptionJSONObjectExceptionpublic ValueIterator<Object> anySequenceFrom(Object source) throws IOException, JSONObjectException
ValueIterator for reading
streaming JSON
content (specifically line-delimited and concatenated variants);
individual values are bound as "Simple" type: Map,
List, String, Number or Boolean.IOExceptionJSONObjectExceptionpublic <T extends TreeNode> ValueIterator<T> treeSequenceFrom(Object source) throws IOException, JSONObjectException
ValueIterator for reading
streaming JSON
content (specifically line-delimited and concatenated variants);
individual values are bound as JSON Trees(of type that configured
TreeCodec, see with(TreeCodec)) supports.IOExceptionJSONObjectExceptionpublic <T extends TreeNode> T createArrayNode()
getTreeCodec().createArrayNode();Note that for call to succeed a
TreeCodec must have been
configured with this instance using with(TreeCodec) method.public <T extends TreeNode> T createObjectNode()
getTreeCodec().createObjectNode();Note that for call to succeed a
TreeCodec must have been
configured with this instance using with(TreeCodec) method.protected final void _writeAndClose(Object value, JsonGenerator g0) throws IOException
IOExceptionprotected JSONWriter _writerForOperation(JsonGenerator gen)
protected JSONReader _readerForOperation(JsonParser p)
protected JsonParser _parser(Object source) throws IOException, JSONObjectException
IOExceptionJSONObjectExceptionprotected JsonParser _initForReading(JsonParser p) throws IOException
IOExceptionprotected JsonGenerator _config(JsonGenerator g)
protected JsonParser _config(JsonParser p)
protected <T> T _closeWithError(Closeable cl, Exception e) throws IOException
IOExceptionprotected void _close(Closeable cl)
protected <T> T _throw(Exception e) throws IOException
IOExceptionprotected void _noTreeCodec(String msg)
Copyright © 2024 FasterXML. All rights reserved.