@Override public T fromJson(JsonReader reader) throws IOException { return fromJson(delegate, reader, path, 0, failOnNotFound); }
@Override public void toJson(JsonWriter writer, T value) throws IOException { toJson(delegate, writer, value, path, 0); }
@Override public JsonAdapter<?> create(Type type, Set<? extends Annotation> annotations, Moshi moshi) { Pair<Wrapped, Set<Annotation>> nextAnnotations = nextAnnotations(annotations, Wrapped.class); if (nextAnnotations == null) return null; JsonAdapter<Object> adapter = moshi.adapter(type, nextAnnotations.second); Wrapped wrapped = nextAnnotations.first; return new WrappedJsonAdapter<>(adapter, wrapped.path(), wrapped.failOnNotFound()); } };
return fromJson(adapter, reader, path, ++index, failOnNotFound); } else { reader.skipValue();
/** * Recursively writes the respective roots forming a json object that resembles the {@code path} * wrapping the type of the {@code adapter}. */ private static <T> void toJson(JsonAdapter<T> adapter, JsonWriter writer, T value, String[] path, int index) throws IOException { if (value != null || writer.getSerializeNulls()) { if (index == path.length) { adapter.toJson(writer, value); } else { writer.beginObject(); writer.name(path[index]); toJson(adapter, writer, value, path, ++index); writer.endObject(); } } else { // If we don't propagate the null value the writer will throw. writer.nullValue(); } } }