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.



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

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.



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

def json_encoder
  @json_encoder
end

.time_precisionObject

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



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

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.



103
104
105
# File 'lib/active_support/json/encoding.rb', line 103

def use_standard_json_time_format
  @use_standard_json_time_format
end

Class Method Details

.const_missing(name) ⇒ Object

Deprecate CircularReferenceError



144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
# File 'lib/active_support/json/encoding.rb', line 144

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



129
130
131
132
133
134
135
136
137
138
139
140
141
# File 'lib/active_support/json/encoding.rb', line 129

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)


117
118
119
120
121
122
123
124
125
126
127
# File 'lib/active_support/json/encoding.rb', line 117

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