Merge pull request #657 from google/jw/no-io

There is no I/O writing to a StringWriter.
This commit is contained in:
Jesse Wilson 2015-06-17 22:15:34 -04:00
commit e8e8b557d2

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();
}