Allow to register different type for json/xmlrpc encoding/decoding

issue3839
review5021003
Use total_ordering

issue3884
review8291003
Fix KeyError when raising digits validation error.

issue3970
review8411002
Fix and add missing registering type for json and xmlrpc

introduced in changeset ec4c234379ab