-
Notifications
You must be signed in to change notification settings - Fork 74
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
Add Nori::StringWithAttributes#as_json #100
base: main
Are you sure you want to change the base?
Add Nori::StringWithAttributes#as_json #100
Conversation
Thanks for your contribution. Wouldn’t this cause serialization to lose the attributes? That could be unexpected. It seems odd to support an interface with an intentionally lossy implementation. If you didn’t care about this, you could explicitly call to_s on the nori::StringWithAttributes before passing it to sidekiq. But it’s not the job of nori to decide to silently truncate data to avoid raising a serialization exception. Sidekiq is telling you there is a real bug in your application because it doesn’t know how to represent a nori string that potentially has attributes. |
That is a good point. Perhaps this should return a Something like { attributes: Array, value: String } |
That might be a start, but I am guessing that would just introduce a problem on the worker side. A complete solution probably requires thinking about deserialization as well. After all, the design of this sidekiq interface is to abstract away the network/process boundary with transparent serialization and deserialization of objects, so the type of the arguments passed by the caller should be the same as the types the receiver gets |
Also good points. Today, with Sidekiq 6 the value is serialized as a Specifically, we are serializing the body from Everything in these Hashes are fine to serialize to JSON as is except for |
I do realize that the But I don't expect Rails would patch this class too so this is an interesting use case. Maybe require "rails"
require "nori"
Nori::StringWithAttributes.new("Hello").as_json.class
# => Nori::StringWithAttributes < String
Nori::StringWithAttributes.new("Hello").to_json.class
# => String < Object |
Fixes #99