Ejemplo n.º 1
0
 @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());
 }
Ejemplo n.º 2
0
 @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());
 }
Ejemplo n.º 3
0
 private static AbstractCharSequenceAssert<?, String> assertBody(RequestBody body)
     throws IOException {
   Buffer buffer = new Buffer();
   body.writeTo(buffer);
   return assertThat(buffer.readByteString().base64());
 }