简体   繁体   English

ActiveModel :: Serializer:选择JSON编码器

[英]ActiveModel::Serializer: Choose JSON encoder

Is there any way to decide which JSON encoder ActiveModel::Serializer uses? 有什么办法可以确定ActiveModel :: Serializer使用哪个JSON编码器? It seems that JSON encoding takes forever, and I'd like to try some other encoder. 似乎JSON编码需要花费很多时间,我想尝试其他编码器。

While Rails won't allow you to do that by default, you can use oj and include this at your Gemfile: 尽管Rails默认不允许您这样做,但是您可以使用oj并将其包含在Gemfile中:

gem 'oj'
gem 'oj_mimic_json'

And it will definitely be faster in these cases. 在这些情况下肯定会更快。

You can read more about the JSON troubles in Rails below: 您可以在下面的Rails中阅读有关JSON问题的更多信息:

And while you're at it, run away from ActiveModel::Serializer and just build your own presenter layer to produce the JSON and be happy. 当您使用它时,请远离ActiveModel::Serializer并仅构建自己的presenter层以生成JSON并感到高兴。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM