public class FlattrObject extends Object implements Serializable, Externalizable
Basically, this is a wrapper around JSONObject
, which takes care for the
JSONException
and also for serialization of JSON structures.
Constructor and Description |
---|
FlattrObject()
Creates a new, empty
FlattrObject . |
FlattrObject(org.json.JSONObject data)
Creates a
FlattrObject from the given JSONObject . |
FlattrObject(String json)
Creates a
FlattrObject from the given JSON string. |
Modifier and Type | Method and Description |
---|---|
String |
get(String key)
Gets a String from the given key.
|
boolean |
getBoolean(String key)
Gets a boolean from the given key.
|
Date |
getDate(String key)
Gets a
Date from the given key. |
FlattrObject |
getFlattrObject(String key)
Gets a
FlattrObject from the given key. |
int |
getInt(String key)
Gets an integer from the given key.
|
org.json.JSONObject |
getJSONObject()
Returns the
JSONObject that represents this FlattrObject . |
long |
getLong(String key)
Gets a long from the given key.
|
Object |
getObject(String key)
Gets an Object from the given key.
|
List<FlattrObject> |
getObjects(String key)
Gets a collection of
FlattrObject from the given key. |
List<String> |
getStrings(String key)
Gets a collection of String from the given key.
|
String |
getSubString(String key,
String subKey)
Gets a String from the given subKey which is a property of the given key.
|
boolean |
has(String key)
Checks if there is a key.
|
void |
put(String key,
Object value)
Changes the key and sets it to the given value.
|
void |
putStrings(String key,
Collection<String> value)
Puts a collection of strings as array object to the given key.
|
void |
readExternal(ObjectInput in) |
String |
toString()
Returns the current state of the
FlattrObject as JSON string. |
void |
writeExternal(ObjectOutput out) |
public FlattrObject()
FlattrObject
.public FlattrObject(org.json.JSONObject data)
FlattrObject
from the given JSONObject
.data
- JSONObject
to use. It is not cloned. It's contents may be
changed by this FlattrObject
.public FlattrObject(String json)
FlattrObject
from the given JSON string.json
- JSON string to initialize the FlattrObject
withpublic boolean has(String key)
key
- Key to check fortrue
if there is such a key (value may still be null
).public Object getObject(String key)
key
- Key to read fromMarshalException
- if there was no such keypublic String get(String key)
key
- Key to read fromMarshalException
- if there was no such keypublic String getSubString(String key, String subKey)
key
- Key of the parent objectsubKey
- Key to read fromMarshalException
- if there was no such key or subKeypublic FlattrObject getFlattrObject(String key)
FlattrObject
from the given key.key
- Key to read fromFlattrObject
that was readMarshalException
- if there was no such keypublic int getInt(String key)
key
- Key to read fromMarshalException
- if there was no such key, or if it did not contain the expected typepublic long getLong(String key)
key
- Key to read fromMarshalException
- if there was no such key, or if it did not contain the expected typepublic boolean getBoolean(String key)
key
- Key to read fromMarshalException
- if there was no such key, or if it did not contain the expected typepublic Date getDate(String key)
Date
from the given key.key
- Key to read fromDate
that was read, or null
if no date was setMarshalException
- if there was no such key, or if it did not contain the expected typepublic List<String> getStrings(String key)
key
- Key to read fromMarshalException
- if there was no such key, or if it did not contain the expected typepublic List<FlattrObject> getObjects(String key)
FlattrObject
from the given key.key
- Key to read fromFlattrObject
MarshalException
- if there was no such key, or if it did not contain the expected typepublic void put(String key, Object value)
key
- Key to write tovalue
- Value to be writtenMarshalException
- if the key could not be changedpublic void putStrings(String key, Collection<String> value)
key
- Key to write tovalue
- Collection of Strings to writeMarshalException
- if the key could not be changedpublic String toString()
FlattrObject
as JSON string.public org.json.JSONObject getJSONObject()
JSONObject
that represents this FlattrObject
. Note that
changes to this JSONObject
will affect the FlattrObject
as well.JSONObject
public void writeExternal(ObjectOutput out) throws IOException
writeExternal
in interface Externalizable
IOException
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
readExternal
in interface Externalizable
IOException
ClassNotFoundException
Copyright © 2010–2014. All rights reserved.