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

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

merged 3 commits into from
Jul 12, 2017

Conversation

marsadle
Copy link

@marsadle marsadle commented Jun 6, 2017

This is a very simple implementation, and you might have something else in mind, but it fixes the issue of jsonapi-serializable no longer calling .to_json as of jsonapi-rb/jsonapi-serializable#56.

Tests pass for currently released versions, as well as master.

Not having this, breaks any requests in Rails that use

render jsonapi: resource

to render data.

Copy link
Member

@beauby beauby left a comment

Choose a reason for hiding this comment

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

Oops, I forgot about that when cutting the last release of jsonapi-serializable. Thanks!

@@ -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.

@beauby
Copy link
Member

beauby commented Jun 6, 2017 via email

Copy link
Member

@beauby beauby left a comment

Choose a reason for hiding this comment

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

Let's go with json = renderer.render(json, options).to_json unless json.is_a?(String) and pinning jsonapi-serializable in the gemspec.
Would you mind taking care of it @mmuehlberger? Otherwise I'll do it myself tomorrow, as this is probably impacting all new users.

@marsadle
Copy link
Author

marsadle commented Jun 8, 2017

@beauby Sure, I'm going to remove the jsonapi-rb dependency, since imho, it's better to not introduce another layer of dependency, just to consolidate gems.

@beauby
Copy link
Member

beauby commented Jun 8, 2017

I understand your concern about the additional layer of dependencies, however I will soon move some bindings into jsonapi-rb, so I'd rather keep it that way.
Other than this, the PR looks good, I'll merge it and add some tests.

@beauby
Copy link
Member

beauby commented Jun 8, 2017

Actually, after investigation, it turns out that the change in jsonapi-serializable we're talking about has not been released yet. Could you expand on the issue you encountered?
We still need this PR for the next release though.

@marsadle
Copy link
Author

marsadle commented Jun 9, 2017

No, the issue was with the master branch, not a released version. I didn't mention this in my PR description, although I thought I did, I'm sorry for the confusion.

I was using master to get the JSONAPI errors.

@beauby beauby merged commit 599031b into jsonapi-rb:master Jul 12, 2017
@beauby
Copy link
Member

beauby commented Jul 12, 2017

Finally merged, thanks again @mmuehlberger.

mdeutsch pushed a commit to patientslikeme/jsonapi-rails that referenced this pull request Jul 21, 2017
* upstream/master:
  Improve specs (jsonapi-rb#33)
  Expose deserialization reverse mapping in controllers (jsonapi-rb#29)
  Update jsonapi-rb to v0.2.1. (jsonapi-rb#32)
  Add dummy app temp files to .gitignore (jsonapi-rb#30)
  Deal with jsonapi-serializable no longer calling to_json (jsonapi-rb#26)
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.

3 participants