implemented state-based customization for serializer

the counterpart to the changes made to the deserializer last commit.

See the added test suite in test/properties.js for example usage.