public class Json extends Object
Constructor and Description |
---|
Json() |
Modifier and Type | Method and Description |
---|---|
static String |
encode(Object object)
Proxy method for getting the Parser and calling encode().
|
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.
|
static <T> T |
parse(byte[] data,
Type type)
Proxy method for getting the Parser and calling parse().
|
public static String encode(Object object)
object
- JSON byte array to be parsed.public static <T> T parse(byte[] data, Type type)
T
- Deserialzed object typedata
- JSON byte array to be parsed.type
- Deserialized type for the JSON datapublic 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.
T
- Deserialzed object typedata
- JSON byte array to be parsedclassType
- The Request implementation class type. This is typically given the calling class as
an argument.Copyright © 2017. All rights reserved.