@Override public RequestBody convert(T value) throws IOException { Buffer buffer = new Buffer(); Writer writer = new OutputStreamWriter(buffer.outputStream(), UTF_8); try { gson.toJson(value, type, writer); writer.flush(); } catch (IOException e) { throw new AssertionError(e); // Writing to Buffer does no I/O. } return RequestBody.create(MEDIA_TYPE, buffer.readByteString()); }
@Override public RequestBody toBody(T value) { Buffer buffer = new Buffer(); Writer writer = new OutputStreamWriter(buffer.outputStream(), Util.UTF_8); try { typeAdapter.toJson(writer, value); writer.flush(); } catch (IOException e) { throw new AssertionError(e); // Writing to Buffer does no I/O. } return RequestBody.create(MEDIA_TYPE, buffer.readByteString()); }
private static AbstractCharSequenceAssert<?, String> assertBody(RequestBody body) throws IOException { Buffer buffer = new Buffer(); body.writeTo(buffer); return assertThat(buffer.readByteString().base64()); }