如何指定 ActiveSupport::JSON.encode 处理嵌套哈希整数键的方式

Ho do I specify how ActiveSupport::JSON.encode handles nested hash integer keys

我不确定这是否是一个错误,或者我是否缺少指定在使用 rails JSON 转换为 JSON 时如何处理嵌套哈希的整数键的选项 ActiveSupport::JSON.encode。问题示例

$ rails console
[deprecated] I18n.enforce_available_locales will default to true in the future. If you really want to skip validation of your locale you can set I18n.enforce_available_locales = false to avoid this message.
Loading development environment (Rails 3.2.22.1)

Frame number: 0/5
[1] pry(main)> ActiveSupport::JSON.encode({outer: {1 => "a"}})
=> "{\"outer\":{\"1\":\"a\"}}"

如您所见,内部哈希键 1 已转换为字符串。我知道有多种选项可以指定如何处理未知的 classes/type 和 ActiveRecord 特定的事情(比如允许与 :include 的连接),但我认为 'native' 类型的整数不会'需要那种东西,默认情况下会处理嵌套。

In JSON, the “keys” must always be strings.

=> a = { 1 => "1" }
#> {1=>"1"}
=> a.to_json
#> "{\"1\":\"1\"}"
=> JSON.parse(a.to_json)
#> {"1"=>"1"}