public class JSONObject extends HashMap<String,Object> implements JSONArtifact
AbstractMap.SimpleEntry<K,V>, AbstractMap.SimpleImmutableEntry<K,V>| Constructor and Description |
|---|
JSONObject()
Constructor
|
| Modifier and Type | Method and Description |
|---|---|
static boolean |
isValidObject(Object object)
Determines whether the supplied object is a valid JSON value
|
static boolean |
isValidType(Class<?> clazz)
Determines whether the supplied class is a valid JSON type
|
Object |
merge(String key,
Object value,
BiFunction<Object,Object,Object> remappingFunction)
Provides merger of the supplied key and value according to logic ni the
supplied remappingFunction
|
static JSONObject |
parse(InputStream is)
Parse the supplied input stream to generate a JSONObject
|
static JSONObject |
parse(Reader reader)
Parse the supplied reader to generate a JSONObject
|
static JSONObject |
parse(String input)
Parse the supplied input to generate a JSONObject
|
Object |
put(String key,
Object value) |
void |
putAll(Map m) |
Object |
putIfAbsent(String key,
Object value) |
Object |
replace(String key,
Object value) |
boolean |
replace(String key,
Object oldValue,
Object value) |
String |
serialize()
Convert this object into a String of JSON text.
|
String |
serialize(boolean verbose) |
void |
serialize(OutputStream os)
Convert this object into a stream of JSON text.
|
void |
serialize(OutputStream os,
boolean verbose)
Convert this object into a stream of JSON text.
|
void |
serialize(Writer writer)
Convert this object into a stream of JSON text.
|
void |
serialize(Writer writer,
boolean verbose)
Convert this object into a stream of JSON text, specifying verbosity.
|
String |
toString() |
String |
toString(StringBuffer sb,
int indent,
int incr)
Abstract method to help with recursive formatting of JSON into a String
|
clear, clone, compute, computeIfAbsent, computeIfPresent, containsKey, containsValue, entrySet, forEach, get, getOrDefault, isEmpty, keySet, merge, remove, remove, replaceAll, size, valuesequals, hashCodepublic static boolean isValidObject(Object object)
object - The object to be tested for validitypublic static boolean isValidType(Class<?> clazz)
clazz - The class to be tested for validitypublic static JSONObject parse(InputStream is) throws IOException
is - InputStream to be parsedIOException - if an error occurs reading or parsing the input streampublic static JSONObject parse(Reader reader) throws IOException
reader - Reader to be parsedIOException - if an error occurs reading or parsing the readerpublic static JSONObject parse(String input) throws IOException
input - InputStream to be parsedIOException - if an error occurs reading or parsing the inputpublic Object merge(String key, Object value, BiFunction<Object,Object,Object> remappingFunction)
key - The key of the object to be mergedvalue - The value of the object to be mergedremappingFunction - The function to control how merger is accomplishedpublic void putAll(Map m)
public Object putIfAbsent(String key, Object value)
putIfAbsent in interface Map<String,Object>putIfAbsent in class HashMap<String,Object>HashMap.putIfAbsent(java.lang.Object, java.lang.Object)public String serialize() throws IOException
JSONArtifactserialize in interface JSONArtifactIOException - Thrown on IO errors during serialization.JSONArtifact.serialize()public String serialize(boolean verbose) throws IOException
serialize in interface JSONArtifactverbose - Whether or not to write the JSON text in a verbose format.IOException - Thrown on IO errors during serialization.JSONArtifact.serialize(boolean)public void serialize(OutputStream os) throws IOException
JSONArtifactserialize in interface JSONArtifactos - The output stream to serialize data to.IOException - Thrown on IO errors during serialization.JSONArtifact.serialize(java.io.OutputStream)public void serialize(OutputStream os, boolean verbose) throws IOException
JSONArtifactserialize in interface JSONArtifactos - The output stream to serialize data to.verbose - Whether or not to write the JSON text in a verbose format.IOException - Thrown on IO errors during serialization.JSONArtifact.serialize(java.io.OutputStream, boolean)public void serialize(Writer writer) throws IOException
JSONArtifactserialize in interface JSONArtifactwriter - The writer which to serialize the JSON text to.IOException - Thrown on IO errors during serialization.JSONArtifact.serialize(java.io.Writer)public void serialize(Writer writer, boolean verbose) throws IOException
JSONArtifactserialize in interface JSONArtifactwriter - The writer which to serialize the JSON text to.verbose - Whether or not to write the JSON text in a verbose format.IOException - Thrown on IO errors during serialization.JSONArtifact.serialize(java.io.Writer, boolean)public String toString()
toString in class AbstractMap<String,Object>JSONObjectpublic String toString(StringBuffer sb, int indent, int incr)
JSONArtifacttoString in interface JSONArtifactsb - Buffer to receive formatted JSON contentindent - The amount of indentation expected in the formatted output.incr - the amount of incremental spacing used for formatted output.JSONArtifact.toString(java.lang.StringBuffer, int, int)Copyright © 2020. All rights reserved.