Module: ActiveSupport::JSON::Encoding
- Defined in:
- lib/active_support/json/encoding.rb
Overview
:nodoc:
Defined Under Namespace
Classes: JSONGemEncoder
Class Attribute Summary collapse
-
.escape_html_entities_in_json ⇒ Object
If true, encode >, <, & as escaped unicode sequences (e.g. > as u003e) as a safety measure.
-
.json_encoder ⇒ Object
Sets the encoder used by Rails to encode Ruby objects into JSON strings in Object#to_json and
ActiveSupport::JSON.encode
. -
.time_precision ⇒ Object
Sets the precision of encoded time values.
-
.use_standard_json_time_format ⇒ Object
If true, use ISO 8601 format for dates and times.
Class Method Summary collapse
-
.const_missing(name) ⇒ Object
Deprecate CircularReferenceError.
- .encode_big_decimal_as_string ⇒ Object
- .encode_big_decimal_as_string=(as_string) ⇒ Object
Class Attribute Details
.escape_html_entities_in_json ⇒ Object
If true, encode >, <, & as escaped unicode sequences (e.g. > as u003e) as a safety measure.
112 113 114 |
# File 'lib/active_support/json/encoding.rb', line 112 def escape_html_entities_in_json @escape_html_entities_in_json end |
.json_encoder ⇒ Object
Sets the encoder used by Rails to encode Ruby objects into JSON strings in Object#to_json and ActiveSupport::JSON.encode
.
120 121 122 |
# File 'lib/active_support/json/encoding.rb', line 120 def json_encoder @json_encoder end |
.time_precision ⇒ Object
Sets the precision of encoded time values. Defaults to 3 (equivalent to millisecond precision)
116 117 118 |
# File 'lib/active_support/json/encoding.rb', line 116 def time_precision @time_precision end |
.use_standard_json_time_format ⇒ Object
If true, use ISO 8601 format for dates and times. Otherwise, fall back to the Active Support legacy format.
108 109 110 |
# File 'lib/active_support/json/encoding.rb', line 108 def use_standard_json_time_format @use_standard_json_time_format end |
Class Method Details
.const_missing(name) ⇒ Object
Deprecate CircularReferenceError
149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 |
# File 'lib/active_support/json/encoding.rb', line 149 def const_missing(name) if name == :CircularReferenceError = "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 SystemStackError else super end end |
.encode_big_decimal_as_string ⇒ Object
134 135 136 137 138 139 140 141 142 143 144 145 146 |
# File 'lib/active_support/json/encoding.rb', line 134 def encode_big_decimal_as_string = \ "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 true end |
.encode_big_decimal_as_string=(as_string) ⇒ Object
122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/active_support/json/encoding.rb', line 122 def encode_big_decimal_as_string=(as_string) = \ "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, end |