|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.apache.pivot.serialization.JSONSerializer
public class JSONSerializer
Implementation of the Serializer
interface that reads data from
and writes data to a JavaScript Object Notation (JSON) file.
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. |
Charset |
getCharset()
|
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. |
int |
getLineNumber()
Returns the line number currently being processed. |
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. |
static String |
toString(Boolean value)
Converts a boolean to a JSON string representation. |
static String |
toString(List<?> value)
Converts a list to a JSON string representation. |
static String |
toString(Map<String,?> value)
Converts a map to a JSON string representation. |
static String |
toString(Number value)
Converts a number to a JSON string representation. |
static String |
toString(Object value)
Converts a object to a JSON string representation. |
static String |
toString(String value)
Converts a string to a JSON string representation. |
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 Charset getCharset()
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 int getLineNumber()
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) throws SerializationException
json
- The JSON value.
SerializationException
public static String parseString(String json) throws SerializationException
json
- The JSON value.
SerializationException
public static Number parseNumber(String json) throws SerializationException
json
- The JSON value.
SerializationException
public static Short parseShort(String json) throws SerializationException
json
- The JSON value.
SerializationException
public static Integer parseInteger(String json) throws SerializationException
json
- The JSON value.
SerializationException
public static Long parseLong(String json) throws SerializationException
json
- The JSON value.
SerializationException
public static Float parseFloat(String json) throws SerializationException
json
- The JSON value.
SerializationException
public static Double parseDouble(String json) throws SerializationException
json
- The JSON value.
SerializationException
public static Boolean parseBoolean(String json) throws SerializationException
json
- The JSON value.
SerializationException
public static List<?> parseList(String json) throws SerializationException
json
- The JSON value.
SerializationException
public static Map<String,?> parseMap(String json) throws SerializationException
json
- The JSON value.
SerializationException
public static String toString(Object value) throws SerializationException
value
- The object to convert.
SerializationException
public static String toString(String value)
value
- The object to convert.
public static String toString(Number value)
value
- The object to convert.
public static String toString(Boolean value)
value
- The object to convert.
public static String toString(List<?> value)
value
- The object to convert.
public static String toString(Map<String,?> value)
value
- The object to convert.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |