Using Coherence API to get POF bytes
Posted
by Bruno.Borges
on Oracle Blogs
See other posts from Oracle Blogs
or by Bruno.Borges
Published on Wed, 24 Oct 2012 03:04:23 +0000
Indexed on
2012/10/24
5:18 UTC
Read the original article
Hit count: 301
/Oracle
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?
© Oracle Blogs or respective owner