Skip to content

Fixes issue with jsonapi-serializable no longer calling to_json #26

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

Merged
merged 3 commits into from
Jul 12, 2017
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/jsonapi/rails/renderer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ def rails_renderer(renderer)
reverse_mapping = request.env[ActionController::REVERSE_MAPPING_KEY]
options = options.merge(_reverse_mapping: reverse_mapping)
json = renderer.render(json, options) unless json.is_a?(String)
json = json.to_json unless json.is_a?(String)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about json = renderer.render(json, options).to_json unless json.is_a?(String) instead?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This works for the master version of jsonapi-serialization, but doesn't with the latest released one. This keeps the gems more independent.

Copy link
Contributor

@smaximov smaximov Jun 6, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@beauby, won't this break code which is pinned to the previous versions of jsonapi-serializable (before .to_json was removed)? If renderer.render returns a string, calling .to_json on it will result in an extra round of escaping.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You guys are obviously right. How about pinning jsonapi-serializable to >= 0.1.3?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about pinning jsonapi-serializable to >= 0.1.3?

I like this better than having an extra .is_a?(String) check.

self.content_type ||= Mime[:jsonapi]
self.response_body = json
end
Expand Down