-
Notifications
You must be signed in to change notification settings - Fork 1
MessageConverter
tylertreat edited this page Jan 17, 2013
·
2 revisions
A MessageConverter is used by RestfulMappingClient to convert REST responses into objects. Infinitum provides several implementations including GsonMessageConverter, SimpleXmlMessageConverter, and JacksonMessageConverter.
The interface has one method, convert, which takes a Class and RestResponse. This methods converts the RestResponse into an instance of the given Class.
The example below shows how GsonMessageConverter is implemented.
public class GsonMessageConverter implements MessageConverter {
private Gson mGson;
public GsonMessageConverter() {
mGson = new Gson();
}
public GsonMessageConverter(Gson gson) {
mGson = gson;
}
@Override
public <T> T convert(Class<T> clazz, RestResponse response) {
return mGson.fromJson(response.getResponseDataAsString(), clazz);
}
}