Call `to_json` on the object to allow overridden methods the first shot

ActiveSupport will call `merge` on the GeneratorState, which resets
the depth back to 0. Then we decrement it again and pass that negative
value to System.arraycopy, which throws an exception.

This fixes the problem in the same way as the pure JSON code: it calls
`to_json` on the passed-in object. This method is implemented /
overridden by ActiveSupport, which then ignores the pretty-printing
completely.