GsonJsonObjectOutput implements ObjectOutput { @Override public void writeObject(Object obj) throws IOException { char[] json = gson.toJson(obj).toCharArray(); writer.write(json, 0, json.length); writer.println(); writer.flush(); json = null; } GsonJsonObjectOutput(OutputStream out);  GsonJsonObjectOutput(Writer writer); @Override void writeBool(boolean v); @Override void writeByte(byte v); @Override void writeShort(short v); @Override void writeInt(int v); @Override void writeLong(long v); @Override void writeFloat(float v); @Override void writeDouble(double v); @Override void writeUTF(String v); @Override void writeBytes(byte[] b); @Override void writeBytes(byte[] b, int off, int len); @Override void writeObject(Object obj); @Override void flushBuffer();  }
@Test public void testWriteObject() throws IOException, ClassNotFoundException { Image image = new Image("http: this.gsonJsonObjectOutput.writeObject(image); this.flushToInput(); Image readObjectForImage = gsonJsonObjectInput.readObject(Image.class); assertThat(readObjectForImage, not(nullValue())); assertThat(readObjectForImage, is(image)); }