This is a backport of #8185 to fix #8182
backport #8185, `#as_json` isolates options when encoding a hash.
Setting options in a custom `#as_json` method had side effects.
Modifications of the `options` hash leaked outside and influenced
the conversion of other objects contained in the hash.
@carlosantoniodasilva could you review this please?