FastJsonObjectInput implements ObjectInput { @Override public Object readObject() throws IOException, ClassNotFoundException { String json = readLine(); return JSON.parse(json); } FastJsonObjectInput(InputStream in);  FastJsonObjectInput(Reader reader); @Override boolean readBool(); @Override byte readByte(); @Override short readShort(); @Override int readInt(); @Override long readLong(); @Override float readFloat(); @Override double readDouble(); @Override String readUTF(); @Override byte[] readBytes(); @Override Object readObject(); @Override T readObject(Class<T> cls); @Override @SuppressWarnings("unchecked") T readObject(Class<T> cls, Type type);  }
@Test public void testReadObject() throws IOException, ClassNotFoundException { fastJsonObjectInput = new FastJsonObjectInput(new StringReader("{ \"name\":\"John\", \"age\":30 }")); Person result = fastJsonObjectInput.readObject(Person.class); assertThat(result, not(nullValue())); assertThat(result.getName(), is("John")); assertThat(result.getAge(), is(30)); }
@Test(expected = EOFException.class) public void testEmptyLine() throws IOException, ClassNotFoundException { fastJsonObjectInput = new FastJsonObjectInput(new StringReader("")); fastJsonObjectInput.readObject(); }
@Test(expected = EOFException.class) public void testEmptySpace() throws IOException, ClassNotFoundException { fastJsonObjectInput = new FastJsonObjectInput(new StringReader(" ")); fastJsonObjectInput.readObject(); }
@Test public void testReadObjectWithoutClass() throws IOException, ClassNotFoundException { fastJsonObjectInput = new FastJsonObjectInput(new StringReader("{ \"name\":\"John\", \"age\":30 }")); JSONObject readObject = (JSONObject) fastJsonObjectInput.readObject(); assertThat(readObject, not(nullValue())); assertThat(readObject.getString("name"), is("John")); assertThat(readObject.getInteger("age"), is(30)); }