Java Code Examples for com.squareup.moshi.Types#equals()

The following examples show how to use com.squareup.moshi.Types#equals() . 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: Util.java    From moshi with Apache License 2.0 4 votes vote down vote up
public static boolean typesMatch(Type pattern, Type candidate) {
  // TODO: permit raw types (like Set.class) to match non-raw candidates (like Set<Long>).
  return Types.equals(pattern, candidate);
}
 
Example 3
Source File: Util.java    From moshi with Apache License 2.0 4 votes vote down vote up
@Override public boolean equals(Object other) {
  return other instanceof ParameterizedType
      && Types.equals(this, (ParameterizedType) other);
}
 
Example 4
Source File: Util.java    From moshi with Apache License 2.0 4 votes vote down vote up
@Override public boolean equals(Object o) {
  return o instanceof GenericArrayType
      && Types.equals(this, (GenericArrayType) o);
}
 
Example 5
Source File: Util.java    From moshi with Apache License 2.0 4 votes vote down vote up
@Override public boolean equals(Object other) {
  return other instanceof WildcardType
      && Types.equals(this, (WildcardType) other);
}