Closed silva96 closed 1 day ago
Hey!
"new(...).to_json"
/ "new.serialize_to_json(...)"
- will return a JSON serialized String, so if you do render json: { .. }
you will get an output of object with value as string, this is something I don't think you expect. The way to solve this String issue, is with Panko::Response
(option 5).
"new.serialize(...)"
/ "new.serialize(...).to_json"
- serialize creates an array of hashes, together with to_json
will return a JSON string on it. For performance reasons it's not recommended to use it, since:
serialize_to_json
/ to_json
- You do it on one pass, See https://panko.dev/docs/design-choices#ojstringwriter for more explanation.Let me know if you have more questions.
Thanks! very clear.
Hey @yosiat , thanks for this answer - I think it deserves a place in the documentation on its own :) What's the equivalent for single object serialization?
ObjectSerializer.new.serialize_to_json(object)
is preferable over ObjectSerializer.new.serialize(object).to_json
, right? In the "getting started" documentation I don't think it's clear which one is recommended.
I think existing documentation could greatly benefit from a page with common use cases, like:
User
with many Comments
) and eager loading;I know most of these things are outside the scope of a serialization library, but they could give hints about possible ways of integrating Panko with the existing rails ecosystem for starters.
Thanks for the great work on this gem!
@metalelf0 I agree with you here that there are too many options to serialize an array and single object. The next major version of Panko (no ETA) should address this with breaking API changes.
For now, I will mark it as documentation
label and will accept PRs for clarifying the documentation.
I'll close this issue, if there any more questions about this topic, please open discussion. If you find bugs - please open new issue.
Hey! After reading the documentation, I was wondering what's the difference between all these options, in terms of the output they give and the performance of each.
In a rails controller:
Thanks in advance!