Closed kukicola closed 9 months ago
The default options should not be changed. Looks like a bug.
I looked into it a bit more. Sadly the observed behaviour is correct. The Oj.generate
call is meant to act like the JSON gem but the JSON gem relies on objects having a to_json
method and using the JSON gem to encode. That requires Oj to set the global defaults.
I realized that was a problem when parsing so the Oj::Parser was created. I have not done the write or encode counterpart to that yet though.
Bottom line is that I'd have to agree that it is a bug but at a fundamental level to mimc the JSON gem. The fix is to implement an Oj::Encoder module where options are contained in the encoder. Then that encoder would be used instead of the global calls. What do you think?
Hello, sorry for the delayed response. I don't know much about Oj internals so it's really hard for me to tell but it seems like a reasonable solution. Anyway, in my case, I just switched to Oj.dump
with some additional options to avoid any unexpected behavior
Thanks for letting me know. The plans for an Encoder are still in the works anyway.
Hello Please take a look at code below, for some reason
mode
before callingOj.generate
is:object
but it becomes:compat
afterwards (other options change as well). I assume it's not the desired behavior? Version:3.13.10