com.heroku.api.parser
Class Json
java.lang.Object
com.heroku.api.parser.Json
public class Json
- extends Object
Constructor Summary |
Json()
|
Method Summary |
static
|
parse(byte[] data,
Class<? extends Request<T>> classType)
Calls Parser.parse() using the generic type T for Request given Request is the interface for the
classType parameter. |
static
|
parse(byte[] data,
Type type)
Proxy method for getting the Parser and calling parse(). |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Json
public Json()
parse
public static <T> T parse(byte[] data,
Type type)
- Proxy method for getting the Parser and calling parse().
- Type Parameters:
T
- Deserialzed object type- Parameters:
data
- JSON byte array to be parsed.type
- Deserialized type for the JSON data
- Returns:
- The JSON data deserialized to T
parse
public static <T> T parse(byte[] data,
Class<? extends Request<T>> classType)
- Calls Parser.parse() using the generic type T for Request given Request is the interface for the
classType parameter. If it can't find an appropriate type, it errors out with a ParseException.
The following code sample illustrates typical usage in the context of a request to Heroku's API.
The byte array is provided from a connection.execute(request) call, which is a JSON response from
the server. getClass() provides the classType, which in this case extends Request. The return
value from the parse method will be App.
public class SampleRequest implements Request {
...
public App getResponse(byte[] data, int status) {
return Json.parse(data, getClass());
}
}
- Parameters:
data
- JSON byte array to be parsedclassType
- The Request implementation class type. This is typically given the calling class as
an argument.
- Returns:
- T
Copyright © 2012. All Rights Reserved.