public byte[] serializeSessionData(CustomRequestSession session,SessionSerializationMetadata metadata) throws IOException {
  byte[] serialized=null;
  try (ByteArrayOutputStream bos=new ByteArrayOutputStream();ObjectOutputStream oos=new ObjectOutputStream(new BufferedOutputStream(bos))){
    oos.writeObject(metadata);
    session.writeObjectData(oos);
    oos.flush();
    serialized=bos.toByteArray();
  }
   return serialized;
}

public byte [ ] serializeSessionData ( CustomRequestSession session , SessionSerializationMetadata metadata ) throws IOException { byte [ ] serialized = null ; try ( ByteArrayOutputStream bos = new ByteArrayOutputStream ( ) ; ObjectOutputStream oos = new ObjectOutputStream ( new BufferedOutputStream ( bos ) ) ) { oos . writeObject ( metadata ) ; session . writeObjectData ( oos ) ; oos . flush ( ) ; serialized = bos . toByteArray ( ) ; } return serialized ; }
method to serialize custom session data
