Skip to content

Commit 714e5d4

Browse files
committed
Change default_json_module: 'oj' to 'json'
1 parent 213a821 commit 714e5d4

File tree

4 files changed

+22
-6
lines changed

4 files changed

+22
-6
lines changed

README.md

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,10 +141,27 @@ SimpleJson.template_paths=["app/views", "app/simple_jsons"]
141141

142142
Note that these paths should not be eager loaded cause using .rb as suffix.
143143

144-
SimpleJson uses Oj as json serializer by default. Modules with `#encode` and `#decode` method can be used here.
144+
SimpleJson uses ActiveSupport::JSON as the default JSON serializer. If you want to change to a module that has `#encode` and `#decode` methods, such as the Oj gem, you can do so as follows.
145145

146146
```ruby
147-
SimpleJson.json_module = ActiveSupport::JSON
147+
148+
# define Custom Json class
149+
# ex. config/initializers/simple_json/json.rb
150+
module SimpleJson
151+
module Json
152+
class Oj
153+
def self.encode(json)
154+
::Oj.dump(json, mode: :rails)
155+
end
156+
157+
def self.decode(json_string)
158+
::Oj.load(json_string, mode: :rails)
159+
end
160+
end
161+
end
162+
end
163+
164+
SimpleJson.json_module = SimpleJson::Json::Oj
148165
```
149166

150167
## The Generator
@@ -283,7 +300,7 @@ Note that render will be performed twice, so using it in production mode is not
283300

284301
## Contributing
285302

286-
Pull requests are welcome on GitHub at https://github.com/aktsk/simple_json.
303+
Pull requests are welcome on GitHub at <https://github.com/aktsk/simple_json>.
287304

288305
## License
289306

lib/simple_json.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,13 @@
88

99
require 'simple_json/migratable'
1010
require 'simple_json/simple_json_renderer_for_migration'
11-
require 'simple_json/json'
1211

1312
module SimpleJson
1413
@config = {
1514
cache_enabled: false,
1615
template_paths: ['app/views'],
1716
cache_key_prefix: 'simple_json/views',
18-
default_json_module: Json::Oj
17+
default_json_module: ActiveSupport::JSON
1918
}
2019

2120
class << self

simple_json.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ Gem::Specification.new do |spec|
2020
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
2121
spec.require_paths = ['lib']
2222

23-
spec.add_dependency 'oj', '~> 3.13'
23+
spec.add_development_dependency 'oj'
2424

2525
spec.add_development_dependency 'action_args'
2626
spec.add_development_dependency 'bundler'

lib/simple_json/json.rb renamed to test/dummy_app/config/initializers/simple_json/json.rb

File renamed without changes.

0 commit comments

Comments
 (0)