Skip to content
Open
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
/pkg/
/spec/reports/
/tmp/
/log/
/benchmark/flamegraphs/
/gemfiles/*.lock

Expand Down
12 changes: 6 additions & 6 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Bundler/OrderedGems:
# Include: **/*.gemspec
Gemspec/RequiredRubyVersion:
Exclude:
- 'oj_serializers.gemspec'
- 'json_serializers.gemspec'

# Offense count: 5
# This cop supports safe autocorrection (--autocorrect).
Expand All @@ -44,21 +44,21 @@ Lint/RedundantDirGlobSort:
# SupportedStyles: strict, consistent
Lint/SymbolConversion:
Exclude:
- 'lib/oj_serializers/serializer.rb'
- 'lib/json_serializers/serializer.rb'

# Offense count: 1
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: AutoCorrect, IgnoreEmptyBlocks, AllowUnusedKeywordArguments.
Lint/UnusedBlockArgument:
Exclude:
- 'lib/oj_serializers/serializer.rb'
- 'lib/json_serializers/serializer.rb'

# Offense count: 2
# This cop supports unsafe autocorrection (--autocorrect-all).
# Configuration parameters: AllowedReceivers.
Lint/UselessDefaultValueArgument:
Exclude:
- 'lib/oj_serializers/serializer.rb'
- 'lib/json_serializers/serializer.rb'

# Offense count: 5
# This cop supports safe autocorrection (--autocorrect).
Expand All @@ -72,7 +72,7 @@ Style/StringLiterals:
# This cop supports safe autocorrection (--autocorrect).
Style/SuperArguments:
Exclude:
- 'lib/oj_serializers/serializer.rb'
- 'lib/json_serializers/serializer.rb'

# Offense count: 1
# This cop supports unsafe autocorrection (--autocorrect-all).
Expand All @@ -88,7 +88,7 @@ Style/SymbolProc:
# SupportedStylesForMultiline: comma, consistent_comma, no_comma
Style/TrailingCommaInArguments:
Exclude:
- 'spec/oj_serializers/sort_attributes_spec.rb'
- 'spec/json_serializers/sort_attributes_spec.rb'

# Offense count: 17
# This cop supports safe autocorrection (--autocorrect).
Expand Down
22 changes: 10 additions & 12 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
## Oj Serializers 3.0.0 (2026-01-02)
## JSON Serializers 3.0.0 (2026-01-02)

### Features ✨

- [Pass user options to children associations](https://github.com/ElMassimo/oj_serializers/commit/d495f06)

## Oj Serializers 2.1.0 (2026-01-02)
## JSON Serializers 2.1.0 (2026-01-02)

### Fixes 🐞

- [Improve sorting by :definition with more than 10 attributes in the list](https://github.com/ElMassimo/oj_serializers/commit/d58cb81) (#25)

## Oj Serializers 2.0.3 (2023-04-19)
## JSON Serializers 2.0.3 (2023-04-19)

### Features ✨

Expand All @@ -20,7 +20,7 @@

- [Allow using `active_model_serializers` in associations](https://github.com/ElMassimo/oj_serializers/commit/501ed4014b564e6f103d2f52d15832fe6706d6a8)

## Oj Serializers 2.0.2 (2023-04-02)
## JSON Serializers 2.0.2 (2023-04-02)

### Features ✨

Expand All @@ -30,7 +30,7 @@

- [Error when defining attributes with options](https://github.com/ElMassimo/oj_serializers/commit/680ab47)

## Oj Serializers 2.0.1 (2023-04-02)
## JSON Serializers 2.0.1 (2023-04-02)

### Features ✨

Expand All @@ -41,7 +41,7 @@

- [Aliased attributes should be sorted by the output key](https://github.com/ElMassimo/oj_serializers/commit/fc6f4c1)

## [Oj Serializers 2.0.0 (2023-03-27)](https://github.com/ElMassimo/oj_serializers/pull/9)
## [JSON Serializers 2.0.0 (2023-03-27)](https://github.com/ElMassimo/oj_serializers/pull/9)

### Features ✨

Expand All @@ -54,20 +54,18 @@

### Breaking Changes

Since returning a `Hash` is more convenient than returning a `Oj::StringWriter`, and performance is comparable, `default_format :hash` is now the default.
Since returning a `Hash` is more convenient and performance is comparable, `default_format :hash` is now the default.

The previous APIs will still be available as `one_as_json` and `many_as_json`, as well as `default_format :json` to make the library work like in version 1.

## Oj Serializers 1.0.2 (2023-03-01) ##
## JSON Serializers 1.0.2 (2023-03-01) ##

* [fix: avoid freezing `ALLOWED_INSTANCE_VARIABLES`](https://github.com/ElMassimo/oj_serializers/commit/ade0302)


## Oj Serializers 1.0.1 (2023-03-01) ##
## JSON Serializers 1.0.1 (2023-03-01) ##

* [fix: avoid caching instances of reloaded classes in development](https://github.com/ElMassimo/oj_serializers/commit/0bd928d64d159926acf6b4d57e3f08b12f6931ce)


## Oj Serializers 1.0.0 (2020-11-05) ##
## JSON Serializers 1.0.0 (2020-11-05) ##

* Initial Release.
15 changes: 7 additions & 8 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
PATH
remote: .
specs:
oj_serializers (3.0.0)
oj (>= 3.14.0)
json_serializers (3.0.0)

GEM
remote: https://rubygems.org/
Expand Down Expand Up @@ -90,7 +89,7 @@ GEM
benchmark-ips (2.14.0)
benchmark-memory (0.2.0)
memory_profiler (~> 1)
bigdecimal (3.2.2)
bigdecimal (4.0.1)
blueprinter (0.30.0)
bson (5.1.1)
builder (3.3.0)
Expand All @@ -116,7 +115,7 @@ GEM
pp (>= 0.6.0)
rdoc (>= 4.0.0)
reline (>= 0.4.2)
json (2.12.2)
json (2.19.2)
jsonapi-renderer (0.2.2)
language_server-protocol (3.17.0.5)
lint_roller (1.1.0)
Expand Down Expand Up @@ -155,10 +154,10 @@ GEM
racc (~> 1.4)
nokogiri (1.18.8-x86_64-linux-gnu)
racc (~> 1.4)
oj (3.16.11)
oj (3.16.16)
bigdecimal (>= 3.0)
ostruct (>= 0.2)
ostruct (0.6.2)
ostruct (0.6.3)
panko_serializer (0.8.3)
activesupport
oj (> 3.11.0, < 4.0.0)
Expand Down Expand Up @@ -296,9 +295,9 @@ DEPENDENCIES
benchmark-memory
blueprinter (~> 0.8)
json
json_serializers!
memory_profiler
mongoid
oj_serializers!
panko_serializer
pry-byebug (~> 3.9)
rails
Expand All @@ -310,4 +309,4 @@ DEPENDENCIES
sqlite3

BUNDLED WITH
2.3.22
2.7.2
14 changes: 6 additions & 8 deletions MIGRATION_GUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,15 @@
[readme]: https://github.com/ElMassimo/oj_serializers/blob/main/README.md
[attributes dsl]: https://github.com/ElMassimo/oj_serializers/blob/main/README.md#attributes-dsl-

[oj]: https://github.com/ohler55/oj
[ams]: https://github.com/rails-api/active_model_serializers
[jsonapi]: https://github.com/jsonapi-serializer/jsonapi-serializer
[panko]: https://github.com/panko-serializer/panko_serializer
[benchmarks]: https://github.com/ElMassimo/oj_serializers/tree/master/benchmarks
[raw_benchmarks]: https://github.com/ElMassimo/oj_serializers/blob/main/benchmarks/document_benchmark.rb
[migration guide]: https://github.com/ElMassimo/oj_serializers/blob/main/MIGRATION_GUIDE.md
[raw_json]: https://github.com/ohler55/oj/issues/542
[trailing_commas]: https://maximomussini.com/posts/trailing-commas/

The DSL of `oj_serializers` is meant to be similar to the one provided by `active_model_serializers` to make the migration process simple,
The DSL of `json_serializers` is meant to be similar to the one provided by `active_model_serializers` to make the migration process simple,
though the goal is not to be a drop-in replacement.

## Rendering 🛠
Expand All @@ -24,7 +22,7 @@ To use the same format in controllers, using the `root`, `serializer`, `each_ser

```ruby
# config/initializers/json.rb
require 'oj_serializers/compat'
require 'json_serializers/compat'
```

Otherwise, use `one` and `many` to serialize objects or enumerables:
Expand Down Expand Up @@ -80,7 +78,7 @@ end

# becomes

class AlbumSerializer < Oj::Serializer
class AlbumSerializer < JsonSerializer
ams_attributes :name, :release

# The serializer class must be explicitly provided.
Expand All @@ -102,7 +100,7 @@ Once your serializer is working as expected, you can further refactor it to be m
Being explicit about where the attributes are coming from makes the serializers easier to understand and more maintainable.

```ruby
class AlbumSerializer < Oj::Serializer
class AlbumSerializer < JsonSerializer
attributes :name

has_many :songs, serializer: SongSerializer
Expand Down Expand Up @@ -140,7 +138,7 @@ In case you need to access path helpers in your serializers, you can use the
following:

```ruby
class BaseJsonSerializer < Oj::Serializer
class BaseJsonSerializer < JsonSerializer
include Rails.application.routes.url_helpers

def default_url_options
Expand All @@ -165,7 +163,7 @@ class ApplicationController < ActionController::Base
before_action { Thread.current[:current_controller] = self }
end

class BaseJsonSerializer < Oj::Serializer
class BaseJsonSerializer < JsonSerializer
def scope
@scope ||= Thread.current[:current_controller]
end
Expand Down
Loading
Loading