Fix serialization of int/str subclasses, e.g. bool

Without this fix, bools would be deserialized as ints, e.g.
getting a key that was set as True would return 1.