Custom attributes serialization and access

Rebased version of #243
Reverted the merge for now. #346 solves a big part of this problem, but is more BC