|
||||||||||
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 java.lang.String |
MIME_TYPE
|
Constructor Summary | |
---|---|
JSONSerializer()
|
|
JSONSerializer(java.nio.charset.Charset charset)
|
|
JSONSerializer(java.lang.String charsetName)
|
Method Summary | |
---|---|
boolean |
getAlwaysDelimitMapKeys()
Returns a flag indicating whether or not map keys will always be quote-delimited. |
static java.lang.Boolean |
getBoolean(java.lang.Object root,
java.lang.String path)
Returns the value at the given path as a boolean. |
static java.lang.Double |
getDouble(java.lang.Object root,
java.lang.String path)
Returns the value at the given path as a double. |
static java.lang.Float |
getFloat(java.lang.Object root,
java.lang.String path)
Returns the value at the given path as a float. |
static java.lang.Integer |
getInteger(java.lang.Object root,
java.lang.String path)
Returns the value at the given path as an integer. |
static List<?> |
getList(java.lang.Object root,
java.lang.String path)
Returns the value at the given path as a list. |
static java.lang.Long |
getLong(java.lang.Object root,
java.lang.String path)
Returns the value at the given path as a long. |
static Map<java.lang.String,?> |
getMap(java.lang.Object root,
java.lang.String path)
Returns the value at the given path as a map. |
java.lang.String |
getMIMEType(java.lang.Object object)
Returns the MIME type of the data read and written by this serializer. |
static java.lang.Number |
getNumber(java.lang.Object root,
java.lang.String path)
Returns the value at the given path as a number. |
static java.lang.Short |
getShort(java.lang.Object root,
java.lang.String path)
Returns the value at the given path as a short. |
static java.lang.String |
getString(java.lang.Object root,
java.lang.String path)
Returns the value at the given path as a string. |
static java.lang.Object |
getValue(java.lang.Object root,
java.lang.String path)
Returns the value at the given path. |
static List<?> |
parseList(java.lang.String string)
Parses a JSON-formatted array value into a list. |
static Map<java.lang.String,?> |
parseMap(java.lang.String string)
Parses a JSON-formatted object value into a map. |
java.lang.Object |
readObject(java.io.InputStream inputStream)
Reads data from a JSON stream. |
java.lang.Object |
readObject(java.io.Reader reader)
Reads data from a JSON stream. |
void |
setAlwaysDelimitMapKeys(boolean alwaysDelimitMapKeys)
Sets a flag indicating that map keys should always be quote-delimited. |
void |
writeObject(java.lang.Object object,
java.io.OutputStream outputStream)
Writes data to a JSON stream. |
void |
writeObject(java.lang.Object object,
java.io.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 java.lang.String MIME_TYPE
public static final int BUFFER_SIZE
Constructor Detail |
---|
public JSONSerializer()
public JSONSerializer(java.lang.String charsetName)
public JSONSerializer(java.nio.charset.Charset charset)
Method Detail |
---|
public java.lang.Object readObject(java.io.InputStream inputStream) throws java.io.IOException, SerializationException
readObject
in interface Serializer<java.lang.Object>
inputStream
- The input stream from which data will be read.
java.io.IOException
SerializationException
readObject(Reader)
public java.lang.Object readObject(java.io.Reader reader) throws java.io.IOException, SerializationException
reader
- The reader from which data will be read.
java.io.IOException
SerializationException
public void writeObject(java.lang.Object object, java.io.OutputStream outputStream) throws java.io.IOException, SerializationException
writeObject
in interface Serializer<java.lang.Object>
object
- outputStream
- The output stream to which data will be written.
java.io.IOException
SerializationException
writeObject(Object, Writer)
public void writeObject(java.lang.Object object, java.io.Writer writer) throws java.io.IOException, SerializationException
object
- The object to serialize. Must be one of the following types:
writer
- The writer to which data will be written.
java.io.IOException
SerializationException
public java.lang.String getMIMEType(java.lang.Object object)
Serializer
getMIMEType
in interface Serializer<java.lang.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.public static java.lang.Object getValue(java.lang.Object root, java.lang.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 java.lang.String getString(java.lang.Object root, java.lang.String path)
root
- path
- getValue(Object, String)
public static java.lang.Number getNumber(java.lang.Object root, java.lang.String path)
root
- path
- getValue(Object, String)
public static java.lang.Short getShort(java.lang.Object root, java.lang.String path)
root
- path
- getValue(Object, String)
public static java.lang.Integer getInteger(java.lang.Object root, java.lang.String path)
root
- path
- getValue(Object, String)
public static java.lang.Long getLong(java.lang.Object root, java.lang.String path)
root
- path
- getValue(Object, String)
public static java.lang.Float getFloat(java.lang.Object root, java.lang.String path)
root
- path
- getValue(Object, String)
public static java.lang.Double getDouble(java.lang.Object root, java.lang.String path)
root
- path
- getValue(Object, String)
public static java.lang.Boolean getBoolean(java.lang.Object root, java.lang.String path)
root
- path
- getValue(Object, String)
public static List<?> getList(java.lang.Object root, java.lang.String path)
root
- path
- getValue(Object, String)
public static Map<java.lang.String,?> getMap(java.lang.Object root, java.lang.String path)
root
- path
- getValue(Object, String)
public static List<?> parseList(java.lang.String string)
string
- A string containing a JSON array (e.g. "[1, 2, 3]").
List
instance containing the parsed JSON data.public static Map<java.lang.String,?> parseMap(java.lang.String string)
string
- A string containing a JSON object (e.g. "{a:1, b:2, c:3}").
Map
instance containing the parsed JSON data.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |