Skip to content

Commit b952ae0

Browse files
Drop MultiJson in favor of stdlib JSON
Closes rails#409, rails#419.
1 parent 2afb881 commit b952ae0

File tree

4 files changed

+6
-22
lines changed

4 files changed

+6
-22
lines changed

README.md

+1-16
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ json.partial! partial: 'posts/post', collection: @posts, as: :post
183183
json.comments @post.comments, partial: 'comments/comment', as: :comment
184184
```
185185

186-
The `as: :some_symbol` is used with partials. It will take care of mapping the passed in object to a variable for the partial. If the value is a collection (either implicitly or explicitly by using the `collection:` option, then each value of the collection is passed to the partial as the variable `some_symbol`. If the value is a singular object, then the object is passed to the partial as the variable `some_symbol`.
186+
The `as: :some_symbol` is used with partials. It will take care of mapping the passed in object to a variable for the partial. If the value is a collection (either implicitly or explicitly by using the `collection:` option, then each value of the collection is passed to the partial as the variable `some_symbol`. If the value is a singular object, then the object is passed to the partial as the variable `some_symbol`.
187187

188188
Be sure not to confuse the `as:` option to mean nesting of the partial. For example:
189189

@@ -274,21 +274,6 @@ environment.rb for example):
274274
Jbuilder.key_format camelize: :lower
275275
```
276276

277-
Faster JSON backends
278-
--------------------
279-
280-
Jbuilder uses MultiJson, which by default will use the JSON gem. That gem is
281-
currently tangled with ActiveSupport's all-Ruby `#to_json` implementation,
282-
which is slow (fixed in Rails >= 4.1). For faster Jbuilder rendering, you can
283-
specify something like the Yajl JSON generator instead. You'll need to include
284-
the `yajl-ruby` gem in your Gemfile and then set the following configuration
285-
for MultiJson:
286-
287-
``` ruby
288-
require 'multi_json'
289-
MultiJson.use :yajl
290-
```
291-
292277
## Contributing to Jbuilder
293278

294279
Jbuilder is the work of many contributors. You're encouraged to submit pull requests, propose

jbuilder.gemspec

-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ Gem::Specification.new do |s|
1010
s.required_ruby_version = '>= 1.9.3'
1111

1212
s.add_dependency 'activesupport', '>= 4.2.0'
13-
s.add_dependency 'multi_json', '>= 1.2'
1413

1514
s.files = `git ls-files`.split("\n")
1615
s.test_files = `git ls-files -- test/*`.split("\n")

lib/jbuilder.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
require 'jbuilder/blank'
33
require 'jbuilder/key_formatter'
44
require 'jbuilder/errors'
5-
require 'multi_json'
5+
require 'json'
66
require 'ostruct'
77

88
class Jbuilder
@@ -247,7 +247,7 @@ def merge!(hash_or_array)
247247

248248
# Encodes the current builder as JSON.
249249
def target!
250-
::MultiJson.dump(@attributes)
250+
::JSON.dump(@attributes)
251251
end
252252

253253
private

test/jbuilder_template_test.rb

+3-3
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ class JbuilderTemplateTest < ActiveSupport::TestCase
195195
end
196196
JBUILDER
197197

198-
assert_equal MultiJson.dump(name: "Hit"), Rails.cache.read("jbuilder/root/cache-key")
198+
assert_equal JSON.dump(name: "Hit"), Rails.cache.read("jbuilder/root/cache-key")
199199

200200
result = render(<<-JBUILDER)
201201
json.cache_root! "cache-key" do
@@ -223,7 +223,7 @@ class JbuilderTemplateTest < ActiveSupport::TestCase
223223
end
224224
JBUILDER
225225

226-
assert_equal MultiJson.dump(%w[ a b c ]), Rails.cache.read("jbuilder/root/cache-key")
226+
assert_equal JSON.dump(%w[ a b c ]), Rails.cache.read("jbuilder/root/cache-key")
227227

228228
assert_equal %w[ a b c ], render(<<-JBUILDER)
229229
json.cache_root! "cache-key" do
@@ -285,7 +285,7 @@ class JbuilderTemplateTest < ActiveSupport::TestCase
285285

286286
private
287287
def render(*args)
288-
MultiJson.load render_without_parsing(*args)
288+
JSON.load render_without_parsing(*args)
289289
end
290290

291291
def render_without_parsing(source, assigns = {})

0 commit comments

Comments
 (0)