Use duck typing in serializer

Closes gh-349