adding deserializing support

First pass. There are hooks missing, and the code is not as clean as it could be, but it's a start. Can I have a sanity check from one of you guys?