@Override public void toJson(JsonWriter writer, T value) throws IOException { toJson(delegate, writer, value, path, 0); }
/** * 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(); } } }