oj_serializers 2.1.0 → 3.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a827275a95a3c81ce1da683105293bda56d4986793460c2e447f65dc44c870cb
4
- data.tar.gz: 525a32c3ef350992b04cbf5ca3040fe037530a748e32fac551cb5457c09c7913
3
+ metadata.gz: 8bbb93696ca1b7eb5e3daac8a7a8eaaf2d66331733ae170a6d2d64f15520a0b7
4
+ data.tar.gz: 9356aad11f17a314aa66d7c99d6428b116ae0d7fcd8e36400b27175e428ab6f0
5
5
  SHA512:
6
- metadata.gz: 775586813cd40602dde589feb39fdbf0694e40df35532e905482cef9d97c2fb54ee00a20602e15c710fae654b649d6294214ae8fff00ea9e6ace802557c76093
7
- data.tar.gz: 51a33d1a021e9d5331c5b1078ee9575ae4c02e08019c60f3c5ce2af5a34f6b6a61e18f6b5da925f5e39538362235f8292b649013d1683964108b5a69f7a361bc
6
+ metadata.gz: 6dab9b921059a3ecc572f58ada7eca96e21c3cfed14ebd7ddc50ba5cd75631aa4621da1402e578b0239908c2268795b6cb449c8c4b41adf590426fc9e3c2b563
7
+ data.tar.gz: 4f68ba68ad0ee15585eff8150b87fc448931b3a2aab2aa55bc3aee7d6ca9800851fa46d94b6d20c27012e3f89829e19b979cbec8d993554039a7857f2e105468
data/CHANGELOG.md CHANGED
@@ -1,3 +1,15 @@
1
+ ## Oj Serializers 3.0.1 (2026-07-17)
2
+
3
+ ### Fixes 🐞
4
+
5
+ - Enable `use_raw_json` before `Oj.optimize_rails` so `JsonValue` is not double-encoded on Rails 8.1+.
6
+
7
+ ## Oj Serializers 3.0.0 (2026-01-02)
8
+
9
+ ### Features ✨
10
+
11
+ - [Pass user options to children associations](https://github.com/ElMassimo/oj_serializers/commit/d495f06)
12
+
1
13
  ## Oj Serializers 2.1.0 (2026-01-02)
2
14
 
3
15
  ### Fixes 🐞
@@ -18,28 +18,28 @@ class ActiveModel::Serializer
18
18
  # OjSerializer: Used internally to write a single object association in :hash mode.
19
19
  #
20
20
  # Returns nothing.
21
- def self.one_as_hash(object)
21
+ def self.one_as_hash(object, options = nil)
22
22
  new(object)
23
23
  end
24
24
 
25
25
  # OjSerializer: Used internally to write an association in :hash mode.
26
26
  #
27
27
  # Returns nothing.
28
- def self.many_as_hash(array)
28
+ def self.many_as_hash(array, options = nil)
29
29
  array.map { |object| new(object) }
30
30
  end
31
31
 
32
32
  # OjSerializer: Used internally to write a single object association in :json mode.
33
33
  #
34
34
  # Returns nothing.
35
- def self.write_one(writer, object)
35
+ def self.write_one(writer, object, options = nil)
36
36
  writer.push_value(new(object))
37
37
  end
38
38
 
39
39
  # OjSerializer: Used internally to write an association in :json mode.
40
40
  #
41
41
  # Returns nothing.
42
- def self.write_many(writer, array)
42
+ def self.write_many(writer, array, options = nil)
43
43
  writer.push_array
44
44
  array.each do |object|
45
45
  write_one(writer, object)
@@ -607,17 +607,17 @@ protected
607
607
  <<~WRITE_ONE
608
608
  if __value = #{value}
609
609
  writer.push_key('#{key}')
610
- #{serializer_class}.write_one(writer, __value)
610
+ #{serializer_class}.write_one(writer, __value, options)
611
611
  end
612
612
  WRITE_ONE
613
613
  when :many
614
614
  <<~WRITE_MANY
615
615
  writer.push_key('#{key}')
616
- #{serializer_class}.write_many(writer, #{value})
616
+ #{serializer_class}.write_many(writer, #{value}, options)
617
617
  WRITE_MANY
618
618
  when :flat
619
619
  <<~WRITE_FLAT
620
- #{serializer_class}.write_to_json(writer, #{value})
620
+ #{serializer_class}.write_to_json(writer, #{value}, options)
621
621
  WRITE_FLAT
622
622
  else
623
623
  raise ArgumentError, "Unknown association type: #{type.inspect}"
@@ -666,11 +666,11 @@ protected
666
666
 
667
667
  case type = options.fetch(:association)
668
668
  when :one
669
- "#{key}: (__value = #{value}) ? #{serializer_class}.one_as_hash(__value) : nil"
669
+ "#{key}: (__value = #{value}) ? #{serializer_class}.one_as_hash(__value, options) : nil"
670
670
  when :many
671
- "#{key}: #{serializer_class}.many_as_hash(#{value})"
671
+ "#{key}: #{serializer_class}.many_as_hash(#{value}, options)"
672
672
  when :flat
673
- "**#{serializer_class}.one_as_hash(#{value})"
673
+ "**#{serializer_class}.one_as_hash(#{value}, options)"
674
674
  else
675
675
  raise ArgumentError, "Unknown association type: #{type.inspect}"
676
676
  end
@@ -4,10 +4,16 @@ require 'oj'
4
4
 
5
5
  # NOTE: We automatically set the necessary configuration unless it had been
6
6
  # explicitly set beforehand.
7
+ #
8
+ # `use_raw_json` must be enabled *before* `Oj.optimize_rails`. Rails 8.1
9
+ # memoizes an option-less encoder when the JSON encoder is assigned (which
10
+ # `Oj.optimize_rails` does), and `Oj::Rails::Encoder` captures `default_options`
11
+ # at construction. Enabling `use_raw_json` afterwards leaves that memoized
12
+ # encoder with `use_raw_json: false`, which double-encodes `JsonValue`.
7
13
  unless Oj.default_options[:use_raw_json]
8
14
  require 'rails'
9
- Oj.optimize_rails
10
15
  Oj.default_options = { mode: :rails, use_raw_json: true }
16
+ Oj.optimize_rails
11
17
  end
12
18
 
13
19
  # NOTE: Add an optimization to make it easier to work with a StringWriter
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module OjSerializers
4
- VERSION = '2.1.0'
4
+ VERSION = '3.0.1'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: oj_serializers
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.0
4
+ version: 3.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Maximo Mussini