Skip to content
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.

MessageConverter Example

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);
    }

}
Clone this wiki locally