Module: ActiveSupport::JSON::Encoding

Defined in:
lib/active_support/json/encoding.rb

Overview

:nodoc:

Defined Under Namespace

Classes: JSONGemEncoder

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.escape_html_entities_in_jsonObject

If true, encode >, <, & as escaped unicode sequences (e.g. > as u003e) as a safety measure.


111
112
113
# File 'lib/active_support/json/encoding.rb', line 111

def escape_html_entities_in_json
  @escape_html_entities_in_json
end

.json_encoderObject

Sets the encoder used by Rails to encode Ruby objects into JSON strings in Object#to_json and ActiveSupport::JSON.encode.


119
120
121
# File 'lib/active_support/json/encoding.rb', line 119

def json_encoder
  @json_encoder
end

.time_precisionObject

Sets the precision of encoded time values. Defaults to 3 (equivalent to millisecond precision)


115
116
117
# File 'lib/active_support/json/encoding.rb', line 115

def time_precision
  @time_precision
end

.use_standard_json_time_formatObject

If true, use ISO 8601 format for dates and times. Otherwise, fall back to the Active Support legacy format.


107
108
109
# File 'lib/active_support/json/encoding.rb', line 107

def use_standard_json_time_format
  @use_standard_json_time_format
end

Class Method Details

.const_missing(name) ⇒ Object

Deprecate CircularReferenceError


148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
# File 'lib/active_support/json/encoding.rb', line 148

def const_missing(name)
  if name == :CircularReferenceError
    message = "The JSON encoder in Rails 4.1 no longer offers protection from circular references. " \
              "You are seeing this warning because you are rescuing from (or otherwise referencing) " \
              "ActiveSupport::Encoding::CircularReferenceError. In the future, this error will be " \
              "removed from Rails. You should remove these rescue blocks from your code and ensure " \
              "that your data structures are free of circular references so they can be properly " \
              "serialized into JSON.\n\n" \
              "For example, the following Hash contains a circular reference to itself:\n" \
              "   h = {}\n" \
              "   h['circular'] = h\n" \
              "In this case, calling h.to_json would not work properly."

    ActiveSupport::Deprecation.warn message

    SystemStackError
  else
    super
  end
end

.encode_big_decimal_as_stringObject


133
134
135
136
137
138
139
140
141
142
143
144
145
# File 'lib/active_support/json/encoding.rb', line 133

def encode_big_decimal_as_string
  message = \
    "The JSON encoder in Rails 4.1 no longer supports encoding BigDecimals as JSON numbers. Instead, " \
    "the new encoder will always encode them as strings.\n\n" \
    "You are seeing this error because you are trying to check the value of the related configuration, " \
    "'active_support.encode_big_decimal_as_string'. If your application depends on this option, you should " \
    "add the 'activesupport-json_encoder' gem to your Gemfile. For now, this option will always be true. " \
    "In the future, it will be removed from Rails, so you should stop checking its value."

  ActiveSupport::Deprecation.warn message

  true
end

.encode_big_decimal_as_string=(as_string) ⇒ Object

Raises:

  • (NotImplementedError)

121
122
123
124
125
126
127
128
129
130
131
# File 'lib/active_support/json/encoding.rb', line 121

def encode_big_decimal_as_string=(as_string)
  message = \
    "The JSON encoder in Rails 4.1 no longer supports encoding BigDecimals as JSON numbers. Instead, " \
    "the new encoder will always encode them as strings.\n\n" \
    "You are seeing this error because you have 'active_support.encode_big_decimal_as_string' in " \
    "your configuration file. If you have been setting this to true, you can safely remove it from " \
    "your configuration. Otherwise, you should add the 'activesupport-json_encoder' gem to your " \
    "Gemfile in order to restore this functionality."

  raise NotImplementedError, message
end