There is no I/O writing to a StringWriter.

This commit is contained in:
Jake Wharton 2015-06-17 22:00:03 -04:00
parent 2cac11b449
commit 032847976c

View File

@ -211,9 +211,13 @@ public abstract class TypeAdapter<T> {
* @param value the Java object to convert. May be null.
* @since 2.2
*/
public final String toJson(T value) throws IOException {
public final String toJson(T value) {
StringWriter stringWriter = new StringWriter();
toJson(stringWriter, value);
try {
toJson(stringWriter, value);
} catch (IOException e) {
throw new AssertionError(e); // No I/O writing to a StringWriter.
}
return stringWriter.toString();
}