T - The typepublic interface JsonReader<T> extends Reader<T>, HasModelReadHandler<T,com.google.gwt.json.client.JSONObject>
The setup of the JsonReader is inspired by the UiBinder and is typically specified as an inner class:
pubilc ModalGirlfriendMediator
{
interface Reader extends JsonReader<ModalGirlfriendMediator> {}
public static final Reader JSON_READER = GWT.create(Reader.class);
// The properties of this POJO
}
JSON data can then be converted to an instance of ModalGirlfriendMediator by
calling
String json = "..."; ModalGirlfriendMediator mgm = ModalGirlfriendMediator.JSON_READER.read(jsonString);
| Modifier and Type | Method and Description |
|---|---|
T |
read(com.google.gwt.json.client.JSONObject jsonObject)
Convert the specified JSON object to an instance of T according to the
annotated properties in T.
|
T |
read(String jsonString)
Convert the specified JSON string to an instance of T according to the
annotated properties in T.
|
List<T> |
readList(com.google.gwt.json.client.JSONArray jsonArray)
Convert the specified JSON array to a list of Ts according to the
annotated properties in T.
|
List<T> |
readList(com.google.gwt.json.client.JSONObject jsonObject)
Convert the specified JSON object to a list of Ts according to the
annotated properties in T.
|
List<T> |
readList(com.google.gwt.json.client.JSONObject jsonObject,
String arrayKey)
Convert the specified JSON object to a list of Ts according to the
annotated properties in T.
|
List<T> |
readList(String jsonString)
Convert the specified JSON string to a list of Ts according to the
annotated properties in T.
|
List<T> |
readList(String jsonString,
String arrayKey)
Convert the specified JSON string to a list of Ts according to the
annotated properties in T.
|
addModelReadHandlerList<T> readList(String jsonString) throws com.google.gwt.json.client.JSONException
Depending on jsonString the following value is returned by this
method:
| jsonString | Result |
|---|---|
null |
null |
| empty / blank string | null |
| empty JSON {} |
null |
| JSON with one key / value, which is null or no array {"foo": null} {"foo": 123} |
null |
| JSON with one key / value, which is an empty array {"foo": []} |
empty list |
| JSON with one key and a non-empty array {"foo": [...]} |
a list of Ts according to the annotated properties in T |
jsonString - The JSON string used as input. May be null.null (see above).com.google.gwt.json.client.JSONException - if the specified string represents no valid JSON dataList<T> readList(String jsonString, String arrayKey) throws com.google.gwt.json.client.JSONException
Depending on jsonString and arrayKey the following value
is returned by this method:
| jsonString | arrayKey | Result |
|---|---|---|
null |
any value | null |
| empty / blank string | any value | null |
| empty JSON {} |
any value | null |
| JSON with a non-existing key {"foo": null} {"foo": 123} {"foo": [...]} |
"bar" | null |
| JSON with the specified key and a value which is null or no array {"foo": null} {"foo": 123} |
"foo" | null |
| JSON with the specified key and a avlue which is an empty array {"foo": []} |
"foo" | empty list |
| JSON with the specified key and a non-empty array {"foo": [...]} |
"foo" | a list of Ts according to the annotated properties in T |
jsonString - The JSON string used as input. May be null.arrayKey - The key containing the JSON array.null (see above).com.google.gwt.json.client.JSONException - if the specified string represents no valid JSON dataList<T> readList(com.google.gwt.json.client.JSONObject jsonObject)
Depending on jsonObject the following value is returned by this
method:
| jsonObject | Result |
|---|---|
null |
null |
| empty JSON {} |
null |
| JSON with one key / value, which is null or no array {"foo": null} {"foo": 123} |
null |
| JSON with one key / value, which is an empty array {"foo": []} |
empty list |
| JSON with one key and a non-empty array {"foo": [...]} |
a list of Ts according to the annotated properties in T |
jsonObject - The JSON object used as input. May be null.null (see above).List<T> readList(com.google.gwt.json.client.JSONObject jsonObject, String arrayKey)
Depending on jsonObject and arrayKey the following value
is returned by this method:
| jsonObject | arrayKey | Result |
|---|---|---|
null |
any value | null |
| empty JSON {} |
any value | null |
| JSON with a non-existing key {"foo": null} {"foo": 123} {"foo": [...]} |
"bar" | null |
| JSON with the specified key and a value which is null or no array {"foo": null} {"foo": 123} |
"foo" | null |
| JSON with the specified key and a avlue which is an empty array {"foo": []} |
"foo" | empty list |
| JSON with the specified key and a non-empty array {"foo": [...]} |
"foo" | a list of Ts according to the annotated properties in T |
jsonObject - The JSON object used as input. May be null.arrayKey - The key containing the JSON array.null (see above).List<T> readList(com.google.gwt.json.client.JSONArray jsonArray)
Depending on jsonArray the following value is returned by this
method:
| jsonArray | Result |
|---|---|
null |
null |
| empty array [] |
empty list |
| Non-empty array {[...]} |
a list of Ts according to the annotated properties in T |
jsonArray - The JSON array used as input. May be null.null (see above).T read(String jsonString) throws com.google.gwt.json.client.JSONException
Depending on jsonString the following value is returned by this
method:
| jsonString | Result |
|---|---|
null |
null |
| empty / blank string | null |
| empty JSON {} |
new instance of T |
| JSON with keys / values {"key": "value", ...} |
an instance of T with the mapped JSON data |
jsonString - The JSON string used as input. May be null.null (see
above).com.google.gwt.json.client.JSONException - if the specified string represents no valid JSON dataT read(com.google.gwt.json.client.JSONObject jsonObject) throws com.google.gwt.json.client.JSONException
Depending on jsonObject the following value is returned by this
method:
| jsonObject | Result |
|---|---|
null |
null |
| empty JSON {} |
new instance of T |
| JSON with keys / values {"key": "value", ...} |
an instance of T with the mapped JSON data |
jsonObject - The JSON object used as input. May be null.null (see
above).com.google.gwt.json.client.JSONException - if the specified string represents no valid JSON dataCopyright © 2012 Harald Pehl. All Rights Reserved.