|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectpivot.serialization.JSONSerializer
public class JSONSerializer
Implementation of the Serializer
interface that reads data from
and writes data to a JavaScript Object Notation (JSON) file.
TODO Wrap reader in a CountingReader that tracks line/character index.
Field Summary | |
---|---|
static int |
BUFFER_SIZE
|
static String |
MIME_TYPE
|
Constructor Summary | |
---|---|
JSONSerializer()
|
|
JSONSerializer(Charset charset)
|
|
JSONSerializer(String charsetName)
|
Method Summary | |
---|---|
static boolean |
containsKey(Object root,
String path)
Tests the existence of a path in a given object. |
static Object |
get(Object root,
String path)
Returns the value at the given path. |
boolean |
getAlwaysDelimitMapKeys()
Returns a flag indicating whether or not map keys will always be quote-delimited. |
static Boolean |
getBoolean(Object root,
String path)
Returns the value at the given path as a boolean. |
static Double |
getDouble(Object root,
String path)
Returns the value at the given path as a double. |
static Float |
getFloat(Object root,
String path)
Returns the value at the given path as a float. |
static Integer |
getInteger(Object root,
String path)
Returns the value at the given path as an integer. |
static List<?> |
getList(Object root,
String path)
Returns the value at the given path as a list. |
static Long |
getLong(Object root,
String path)
Returns the value at the given path as a long. |
static Map<String,?> |
getMap(Object root,
String path)
Returns the value at the given path as a map. |
String |
getMIMEType(Object object)
Returns the MIME type of the data read and written by this serializer. |
static Number |
getNumber(Object root,
String path)
Returns the value at the given path as a number. |
static Short |
getShort(Object root,
String path)
Returns the value at the given path as a short. |
static String |
getString(Object root,
String path)
Returns the value at the given path as a string. |
static Object |
getValue(Object root,
String path)
Deprecated. This method is deprecated; use get(Object, String) instead. |
static Object |
parse(String json)
Converts a JSON value to a Java object. |
static Boolean |
parseBoolean(String json)
Converts a JSON value to a boolean. |
static Double |
parseDouble(String json)
Converts a JSON value to a double. |
static Float |
parseFloat(String json)
Converts a JSON value to a float. |
static Integer |
parseInteger(String json)
Converts a JSON value to a integer. |
static List<?> |
parseList(String json)
Converts a JSON value to a list. |
static Long |
parseLong(String json)
Converts a JSON value to a long. |
static Map<String,?> |
parseMap(String json)
Converts a JSON value to a map. |
static Number |
parseNumber(String json)
Converts a JSON value to a number. |
static Short |
parseShort(String json)
Converts a JSON value to a short. |
static String |
parseString(String json)
Converts a JSON value to a string. |
static Object |
put(Object root,
String path,
Object value)
Sets the value at the given path. |
Object |
readObject(InputStream inputStream)
Reads data from a JSON stream. |
Object |
readObject(Reader reader)
Reads data from a JSON stream. |
static Object |
remove(Object root,
String path)
Removes the value at the given path. |
void |
setAlwaysDelimitMapKeys(boolean alwaysDelimitMapKeys)
Sets a flag indicating that map keys should always be quote-delimited. |
void |
writeObject(Object object,
OutputStream outputStream)
Writes data to a JSON stream. |
void |
writeObject(Object object,
Writer writer)
Writes data to a JSON stream. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final String MIME_TYPE
public static final int BUFFER_SIZE
Constructor Detail |
---|
public JSONSerializer()
public JSONSerializer(String charsetName)
public JSONSerializer(Charset charset)
Method Detail |
---|
public Object readObject(InputStream inputStream) throws IOException, SerializationException
readObject
in interface Serializer<Object>
inputStream
- The input stream from which data will be read.
IOException
SerializationException
readObject(Reader)
public Object readObject(Reader reader) throws IOException, SerializationException
reader
- The reader from which data will be read.
IOException
SerializationException
public void writeObject(Object object, OutputStream outputStream) throws IOException, SerializationException
writeObject
in interface Serializer<Object>
object
- outputStream
- The output stream to which data will be written.
IOException
SerializationException
writeObject(Object, Writer)
public void writeObject(Object object, Writer writer) throws IOException, SerializationException
object
- The object to serialize. Must be one of the following types:
writer
- The writer to which data will be written.
IOException
SerializationException
public String getMIMEType(Object object)
Serializer
getMIMEType
in interface Serializer<Object>
object
- If provided, allows the serializer to attach parameters to the returned
MIME type containing more detailed information about the data. If
null, the base MIME type is returned.public boolean getAlwaysDelimitMapKeys()
public void setAlwaysDelimitMapKeys(boolean alwaysDelimitMapKeys)
alwaysDelimitMapKeys
- true to bound map keys in double quotes; false to
only quote-delimit keys as necessary.@Deprecated public static Object getValue(Object root, String path)
get(Object, String)
instead.
root
- The root object; must be an instance of Map
or List
.path
- The path to the value, in JavaScript path notation.
public static Object get(Object root, String path)
root
- The root object; must be an instance of Map
or List
.path
- The path to the value, in JavaScript path notation.
public static String getString(Object root, String path)
root
- path
- getValue(Object, String)
public static Number getNumber(Object root, String path)
root
- path
- getValue(Object, String)
public static Short getShort(Object root, String path)
root
- path
- getValue(Object, String)
public static Integer getInteger(Object root, String path)
root
- path
- getValue(Object, String)
public static Long getLong(Object root, String path)
root
- path
- getValue(Object, String)
public static Float getFloat(Object root, String path)
root
- path
- getValue(Object, String)
public static Double getDouble(Object root, String path)
root
- path
- getValue(Object, String)
public static Boolean getBoolean(Object root, String path)
root
- path
- getValue(Object, String)
public static List<?> getList(Object root, String path)
root
- path
- getValue(Object, String)
public static Map<String,?> getMap(Object root, String path)
root
- path
- getValue(Object, String)
public static Object put(Object root, String path, Object value)
root
- path
- value
-
public static Object remove(Object root, String path)
root
- path
-
public static boolean containsKey(Object root, String path)
root
- path
-
public static Object parse(String json)
json
- The JSON value.
public static String parseString(String json)
json
- The JSON value.
public static Number parseNumber(String json)
json
- The JSON value.
public static Short parseShort(String json)
json
- The JSON value.
public static Integer parseInteger(String json)
json
- The JSON value.
public static Long parseLong(String json)
json
- The JSON value.
public static Float parseFloat(String json)
json
- The JSON value.
public static Double parseDouble(String json)
json
- The JSON value.
public static Boolean parseBoolean(String json)
json
- The JSON value.
public static List<?> parseList(String json)
json
- The JSON value.
public static Map<String,?> parseMap(String json)
json
- The JSON value.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |