Quantcast
Channel: Alltop RSS feed for enterprise.alltop.com
Viewing all articles
Browse latest Browse all 58520

Using Coherence API to get POF bytes

$
0
0

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("some.name@domain.com");
            
   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?


Viewing all articles
Browse latest Browse all 58520

Trending Articles