Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix AM::Serializers::JSON#as_json method for timestamps #31503

Merged
merged 1 commit into from
Aug 11, 2018

Conversation

bogdan
Copy link
Contributor

@bogdan bogdan commented Dec 19, 2017

According to doc the method should return
non-json compatible types as strings.

The original idea behind as_json is that:

object.as_json == JSON.parse(object.to_json)

This patch fixes the compatibility for types that are not supported by JSON.
Also this patch makes Hash#as_json compatible AR::Base#as_json:

{created_at: Time.now}.as_json # => {"created_at": "2010-10-13T22:05:30.000-07:00"}

@rails-bot
Copy link

r? @eileencodes

(@rails-bot has picked a reviewer for you, use r? to override)

According to doc the method should return
non-json compatible types as strings.
@bogdan
Copy link
Contributor Author

bogdan commented Feb 23, 2018

@eileencodes any thoughts on this bugfix?

@eileencodes eileencodes merged commit 09e1452 into rails:master Aug 11, 2018
bogdanvlviv added a commit to bogdanvlviv/rails that referenced this pull request Aug 11, 2018
```
...
(snip)
............F
Failure:
JsonSerializationTest#test_as_json_should_return_a_hash_if_include_root_
in_json_is_true [/home/travis/build/rails/rails/activemodel/test/cases/serializers/json_serialization_test.rb:145]:
Expected: 2006-08-01 00:00:00 UTC
  Actual: "2006-08-01T00:00:00.000Z"
rails test home/travis/build/rails/rails/activemodel/test/cases/serializers/json_serialization_test.rb:136
(snip)
...
```

Related to rails#31503
@bogdanvlviv bogdanvlviv mentioned this pull request Aug 11, 2018
@bogdanvlviv
Copy link
Contributor

How about adding changelog entry for this change?

bogdanvlviv added a commit to bogdanvlviv/rails that referenced this pull request Aug 12, 2018
eileencodes added a commit that referenced this pull request Aug 12, 2018
@prathamesh-sonpatki
Copy link
Member

Isn't it backward incompatible change?

thomasleese added a commit to alphagov/email-alert-api that referenced this pull request Jan 15, 2020
We were relying on old behaviour of as_json which is that it would
return a date object for dates rather than a string (since JSON doesn't
support date objects).

See rails/rails#31503 for more details.
oscarwyatt pushed a commit to alphagov/email-alert-api that referenced this pull request Feb 24, 2020
We were relying on old behaviour of as_json which is that it would
return a date object for dates rather than a string (since JSON doesn't
support date objects).

See rails/rails#31503 for more details.
MuriloDalRi pushed a commit to alphagov/email-alert-api that referenced this pull request Feb 27, 2020
We were relying on old behaviour of as_json which is that it would
return a date object for dates rather than a string (since JSON doesn't
support date objects).

See rails/rails#31503 for more details.
pixeltrix added a commit to alphagov/whitehall that referenced this pull request Jan 3, 2021
In rails/rails#31503 the output of as_json was fixed to make sure that
any returned types were JSON-compatible, e.g. symbols and timestamps
are now converted to strings.
thomasleese pushed a commit to alphagov/whitehall that referenced this pull request Jan 12, 2021
In rails/rails#31503 the output of as_json was fixed to make sure that
any returned types were JSON-compatible, e.g. symbols and timestamps
are now converted to strings.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants