Java Code Examples for com.squareup.moshi.JsonAdapter#Factory

The following examples show how to use com.squareup.moshi.JsonAdapter#Factory . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DefaultOnDataMismatchAdapter.java    From moshi-lazy-adapters with Apache License 2.0 5 votes vote down vote up
/** Builds an adapter that fallbacks to a default value in case there's a mismatch. */
public static <T> JsonAdapter.Factory newFactory(final Type type, final T defaultValue) {
  return new Factory() {
    @Override public JsonAdapter<?> create(Type requestedType,
        Set<? extends Annotation> annotations, Moshi moshi) {
      if (Types.equals(type, requestedType)) {
        JsonAdapter<T> delegate = moshi.nextAdapter(this, type, annotations);
        return new DefaultOnDataMismatchAdapter<>(delegate, defaultValue);
      }

      return null;
    }
  };
}
 
Example 2
Source File: MoshiJsonAdapterFactory.java    From okuki with Apache License 2.0 4 votes vote down vote up
public static JsonAdapter.Factory create() {
    return new AutoValueMoshi_MoshiJsonAdapterFactory();
}
 
Example 3
Source File: DefaultOnDataMismatchAdapterTest.java    From moshi-lazy-adapters with Apache License 2.0 4 votes vote down vote up
private JsonAdapter.Factory newFruitFactory() {
  return DefaultOnDataMismatchAdapter.newFactory(Fruit.class, null);
}
 
Example 4
Source File: DefaultOnDataMismatchAdapterTest.java    From moshi-lazy-adapters with Apache License 2.0 4 votes vote down vote up
private Moshi buildMoshi(JsonAdapter.Factory factory) {
  return new Moshi.Builder()
      .add(factory)
      .build();
}
 
Example 5
Source File: DataFactories.java    From moshi-lazy-adapters with Apache License 2.0 4 votes vote down vote up
public static JsonAdapter.Factory create() {
  return new AutoValueMoshi_DataFactories();
}
 
Example 6
Source File: AutoValueMoshiAdapterFactory.java    From android with Apache License 2.0 4 votes vote down vote up
public static JsonAdapter.Factory create() {
  return new AutoValueMoshi_AutoValueMoshiAdapterFactory();
}