@Test public void encode() throws Exception { Object bean = new TestBean("xiaoming", 20); byte[] data = new ObjectEncoder().encode(bean); Object obj = new ObjectDecoder().decode(data); assertTrue(obj instanceof TestBean); assertEquals(bean, obj); ByteBuffer buffer = new ObjectEncoder().encodeBuf(bean); obj = new ObjectDecoder().decode(buffer); assertTrue(obj instanceof TestBean); assertEquals(bean, obj); }
@Override public byte[] encode(Object object) throws Exception { ByteArrayOutputStream bos = new ByteArrayOutputStream(); try (ObjectOutputStream oos = createObjectOutputStream(bos)) { oos.writeObject(object); return bos.toByteArray(); } }
ObjectEncoder extends AbstractSerializableEncoder { @Override public byte[] encode(Object object) throws Exception { ByteArrayOutputStream bos = new ByteArrayOutputStream(); try (ObjectOutputStream oos = createObjectOutputStream(bos)) { oos.writeObject(object); return bos.toByteArray(); } } }
ObjectEncoder extends AbstractSerializableEncoder { @Override public byte[] encode(Object object) throws Exception { ByteArrayOutputStream bos = new ByteArrayOutputStream(); try (ObjectOutputStream oos = createObjectOutputStream(bos)) { oos.writeObject(object); return bos.toByteArray(); } }  }
ObjectEncoder extends AbstractSerializableEncoder { @Override public byte[] encode(Object object) throws Exception { ByteArrayOutputStream bos = new ByteArrayOutputStream(); try (ObjectOutputStream oos = createObjectOutputStream(bos)) { oos.writeObject(object); return bos.toByteArray(); } }  @Override byte[] encode(Object object); }
ObjectEncoder extends AbstractSerializableEncoder { @Override public byte[] encode(Object object) throws Exception { ByteArrayOutputStream bos = new ByteArrayOutputStream(); try (ObjectOutputStream oos = createObjectOutputStream(bos)) { oos.writeObject(object); return bos.toByteArray(); } }  @Override byte[] encode(Object object);  }