Fix oj/rails conflict #166
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #161
This bug only occurs when both
oj
andrails
are loaded. The code works fine with eitheroj
orrails
. I've added tests for these conflicts, they run in sub-processes so that they're isolated.The issue here is that a custom
to_json
definition isn't honored when objects are in an array. The 'ideal' fix for this must be applied in eitheroj
orrails
. After a bit of experimentation, I think the simplest solution on our end is to just circumvent the problem. This PR removes theMessage
class so that we're relying solely on Ruby core classes for JSON generation. This way, if eitheroj
orrails
(or any other gem that monkey patches JSON generation) misbehave, it'll be a widespread problem (affects eitherArray
orHash
) and not just local to our use case.One downside here is that we'll be generating json for each message twice - once for checking the size, and another time when actually sending the message to segment. This wasn't the case with the earlier solution because our custom
to_json
definition cached this value. I think this is acceptable though, it isn't a huge penalty and working around it wouldn't be trivial.