This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.uber.retrofit2.adapters.network.exception; | |
import android.support.annotation.NonNull; | |
import java.io.IOException; | |
import okhttp3.Call; | |
import okhttp3.Callback; | |
import okhttp3.Request; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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 { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class UsingRave { | |
public static void main(String[] args) { | |
MyModel myModel = new MyModel(“Validate me please!”); | |
try { | |
Rave.getInstance().validate(myModel); | |
} catch (RaveException e) { | |
// This response didn't pass RAVE validation, throw an exception. | |
throw new RuntimeException(e); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Rider { | |
@NonNull private String firstName; | |
@NonNull private String lastName; | |
public Rider(@NonNull String firstname, @NonNull String lastName) { | |
this.firstName = firstName; | |
this.lastName = lastName; | |
} | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Validated(factory = RaveValidatorFactory.class) | |
public class MyModel { | |
@NonNull private String someString; | |
public MyModel(@NonNull String someString) { | |
this.someString = someString; | |
} | |
@NonNull |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class UsingRave { | |
public static void main(String[] args) { | |
MyModel myModel = new MyModel(“Validate me please!”); | |
Rave.validate(myModel); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* A factory class capable of creating a validator whose implementation generated at annotation processing time. | |
*/ | |
public final class RaveValidatorFactory implements ValidatorFactory { | |
@NonNull | |
@Override | |
public BaseValidator generateValidator() { | |
return new RaveValidatorFactory_Generated_Validator(); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public final class RaveValidatorFactory_Generated_Validator extends BaseValidator { | |
RaveValidatorFactory_Generated_Validator() { | |
addSupportedClass(MyModel.class); | |
registerSelf(); | |
} | |
@Override | |
protected void validateAs(@NonNull Object object, @NonNull Class<?> clazz, @NonNull ExclusionStrategy exclusionStrategy) throws InvalidModelException { | |
if (!clazz.isInstance(object)) { | |
throw new IllegalArgumentException(object.getClass().getCanonicalName() + "is not of type" + clazz.getCanonicalName()); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def versions = [ retrofit: ‘2.4.0', support: '27.1.1'] | |
def retrofit = [ | |
adapter: [ rxjava2: "com.squareup.retrofit2:adapter-rxjava2:${versions.retrofit}" ], | |
converter: [ moshi: "com.squareup.retrofit2:converter-moshi:${versions.retrofit}" ], | |
core: "com.squareup.retrofit2:retrofit:${versions.retrofit}" | |
] | |
def support = [ | |
appcompat: "com.android.support:appcompat-v7:${versions.support}", |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
apply plugin: ‘com.android.application’ | |
dependencies { | |
implementation deps.support.appcompat | |
implementation deps.retrofit.core | |
implementation deps.retrofit.adapter.rxjava2 | |
implementation deps.retrofit.converter.moshi | |
} |
OlderNewer