    # File lib/json/common.rb, line 200
      def generate(obj, opts = nil)
        if State === opts
          state, opts = opts, nil
        else
          state = SAFE_STATE_PROTOTYPE.dup
        end
        if opts
          if opts.respond_to? :to_hash
            opts = opts.to_hash
          elsif opts.respond_to? :to_h
            opts = opts.to_h
          else
            raise TypeError, "can't convert #{opts.class} into Hash"
          end
          state = state.configure(opts)
        end
        state.generate(obj)
      end