Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Model of Rider
* A converter factory that uses Rave to validate responses from the network. In the event that a response doesn't
* validate an exception is thrown to consumers.
* NOTE: This is a forwarding converter that delegates to another converter that should convert Java Objects
* into JSON and back. This converter must registered to your Retrofit instance before any other converter it might
* delegate to.
final class RaveConverterFactory extends Converter.Factory {
static RaveConverterFactory create() {
return new RaveConverterFactory();
public Converter<ResponseBody, ?> responseBodyConverter(
Type type, Annotation[] annotations, Retrofit retrofit) {
Converter<ResponseBody, ?> delegateConverter = retrofit.nextResponseBodyConverter(this, type, annotations);
return new RaveResponseConverter(delegateConverter);
* A converter that validates responses received from the network using rave.
private static final class RaveResponseConverter implements Converter<ResponseBody, Object> {
private final Converter<ResponseBody, ?> delegateConverter;
RaveResponseConverter(Converter<ResponseBody, ?> delegateConverter) {
this.delegateConverter = delegateConverter;
public Object convert(ResponseBody value) throws IOException {
Object convert = delegateConverter.convert(value);
try {
} catch (RaveException e) {
// This response didn't pass RAVE validation, throw an exception.
throw new RuntimeException(e);
return convert;
public class Ride {
Url getUrl() {
return this.url;
boolean hasValidUrl() {
Uri url = getUrl();
if (url != null) {
return URLUtil.isValidUrl(url.toString());
} else {
return true;
public class Rider {
private String firstName;
private String lastName;
private String phoneNumber;
public Rider(String firstName, String lastName, String phoneNumber) {
this.firstName = firstName;
this.lastName = lastName;
this.phoneNumber = phoneNumber;
public String firstName() {
return firstName;
public String lastName() {
return lastName;
public String phoneNumber() {
return phoneNumber;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment