File tree Expand file tree Collapse file tree 2 files changed +13
-4
lines changed
activerecord/lib/active_record Expand file tree Collapse file tree 2 files changed +13
-4
lines changed Original file line number Diff line number Diff line change 1
1
# frozen_string_literal: true
2
2
3
+ require "active_support/json"
4
+
3
5
module ActiveRecord
4
6
module Coders # :nodoc:
5
7
class JSON # :nodoc:
6
- def initialize ( options = { } )
7
- @options = options
8
+ DEFAULT_OPTIONS = { escape : false } . freeze
9
+
10
+ def initialize ( options = nil )
11
+ @options = options ? DEFAULT_OPTIONS . merge ( options ) : DEFAULT_OPTIONS
12
+ @encoder = ActiveSupport ::JSON ::Encoding . json_encoder . new ( options )
8
13
end
9
14
10
15
def dump ( obj )
11
- ActiveSupport :: JSON . encode ( obj )
16
+ @encoder . encode ( obj )
12
17
end
13
18
14
19
def load ( json )
Original file line number Diff line number Diff line change 1
1
# frozen_string_literal: true
2
2
3
+ require "active_support/json"
4
+
3
5
module ActiveRecord
4
6
module Type
5
7
class Json < ActiveModel ::Type ::Value
@@ -14,8 +16,10 @@ def deserialize(value)
14
16
ActiveSupport ::JSON . decode ( value ) rescue nil
15
17
end
16
18
19
+ JSON_ENCODER = ActiveSupport ::JSON ::Encoding . json_encoder . new ( escape : false )
20
+
17
21
def serialize ( value )
18
- ActiveSupport :: JSON . encode ( value ) unless value . nil?
22
+ JSON_ENCODER . encode ( value ) unless value . nil?
19
23
end
20
24
21
25
def changed_in_place? ( raw_old_value , new_value )
You can’t perform that action at this time.
0 commit comments