Someone raised the question on how to use the Coherence API to get the bytes of an object in POF (Portable Object Format) programatically. So I came up with this small code that shows the very cool API simple usage :-)
SimplePofContext spc = new SimplePofContext();
spc.registerUserType(0, User.class, new UserSerializer());
// consider UserSerializer as an implementation of PofSerializer
User u = new User();
u.setId(21);
u.setName("Some Name");
u.setEmail("
[email protected]");
ByteArrayOutputStream baos = new ByteArrayOutputStream();
DataOutput dataOutput = new DataOutputStream(baos);
BufferOutput bufferOutput = new WrapperBufferOutput(dataOutput);
spc.serialize(bufferOutput, u);
byte[] byteArray = baos.toByteArray();
System.out.println(Arrays.toString(byteArray));
Easy, isn't?