JsonHelper { public static byte[] toBytes(Object object) { return StringHelper.getBytes(toJson(object)); }  static byte[] toBytes(Object object); static String toJson(Object object); static T fromJson(String json, Class<T> clazz); static T fromJson(byte[] bytes, Class<T> clazz);  }
@Test public void toBytes() throws UnsupportedEncodingException { Bean bean = new Bean(); bean.setA("aaaa"); bean.setB(123); bean.setC(new Date(1000000L)); byte[] bytes = JsonHelper.toBytes(bean); byte[] originBytes = "{\"a\":\"aaaa\",\"b\":123,\"c\":\"Jan 1, 1970 8:16:40 AM\"}".getBytes("UTF-8"); Assert.assertEquals(bytes.length, originBytes.length); for (int i = 0; i < bytes.length;i++) { Assert.assertEquals(bytes[i], originBytes[i]); } }