Custom attributes serialization and access

Rebased version of #243