Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 20 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,10 +141,27 @@ SimpleJson.template_paths=["app/views", "app/simple_jsons"]

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

SimpleJson uses Oj as json serializer by default. Modules with `#encode` and `#decode` method can be used here.
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.

```ruby
SimpleJson.json_module = ActiveSupport::JSON

# define Custom Json class
# ex. config/initializers/simple_json/json.rb
module SimpleJson
module Json
class Oj
def self.encode(json)
::Oj.dump(json, mode: :rails)
end

def self.decode(json_string)
::Oj.load(json_string, mode: :rails)
end
end
end
end

SimpleJson.json_module = SimpleJson::Json::Oj
```

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

## Contributing

Pull requests are welcome on GitHub at https://github.com/aktsk/simple_json.
Pull requests are welcome on GitHub at <https://github.com/aktsk/simple_json>.

## License

Expand Down
3 changes: 1 addition & 2 deletions lib/simple_json.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,13 @@

require 'simple_json/migratable'
require 'simple_json/simple_json_renderer_for_migration'
require 'simple_json/json'

module SimpleJson
@config = {
cache_enabled: false,
template_paths: ['app/views'],
cache_key_prefix: 'simple_json/views',
default_json_module: Json::Oj
default_json_module: ActiveSupport::JSON
}

class << self
Expand Down
2 changes: 1 addition & 1 deletion simple_json.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Gem::Specification.new do |spec|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
spec.require_paths = ['lib']

spec.add_dependency 'oj', '~> 3.13'
spec.add_development_dependency 'oj'

spec.add_development_dependency 'action_args'
spec.add_development_dependency 'bundler'
Expand Down
File renamed without changes.