improve the serialization of custom user models
Merge pull request #3307 from xabbuh/issue-3165

improve the serialization of custom user models