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

@rails-bot rails-bot commented Dec 19, 2017

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 bogdan force-pushed the bogdan:timestamp-as-json branch to 2e5cb98 Dec 21, 2017
@bogdan
Copy link
Contributor Author

@bogdan bogdan commented Feb 23, 2018

@eileencodes any thoughts on this bugfix?

@eileencodes eileencodes merged commit 09e1452 into rails:master Aug 11, 2018
2 checks passed
2 checks passed
codeclimate All good!
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
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

@bogdanvlviv bogdanvlviv commented Aug 11, 2018

How about adding changelog entry for this change?

bogdanvlviv added a commit to bogdanvlviv/rails that referenced this pull request Aug 12, 2018
Related to rails#31503
eileencodes added a commit that referenced this pull request Aug 12, 2018
Add changelog entry for #31503 [ci skip]
@prathamesh-sonpatki
Copy link
Member

@prathamesh-sonpatki prathamesh-sonpatki commented Mar 29, 2019

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 added 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 added 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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

5 participants
You can’t perform that action at this time.