Monday, January 17, 2011

Serialization in to doucment item

Utility function to serialize\deserialize java object in to the domino document item. This object will be possible to read with another languages like LotusScript and so on.
    public static void serializeObject(Document document, String itemName, Serializable o) 
throws IOException, NotesException{
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        ObjectOutput out = new ObjectOutputStream(bos);  
        out.writeObject(o);
        byte[] oByte = bos.toByteArray();
       
        document.replaceItemValueCustomDataBytes(itemName, o.getClass().getName(), oByte);
    }
   
    public static Object deSerializeObject(Document document, String itemName, String oTypeName) 
throws IOException, NotesException, ClassNotFoundException{
        byte[] oByte = document.getItemValueCustomDataBytes(itemName, oTypeName);
       
        ByteArrayInputStream bis = new ByteArrayInputStream(oByte);
        ObjectInput in = new ObjectInputStream(bis);
        Object o = in.readObject();

        return o;
    }

No comments: