Added support for an optional serializer.

Hi Fabian,

I added the option of passing a serializer.
I also added some tests to make sure it works.

Let me know if you are interested in merging it and releasing a new version on pypi.

Thanks
Michael
That is fixed.