-
Notifications
You must be signed in to change notification settings - Fork 216
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
Problem when using oj
as JSON library.
#166
Comments
Firstly, thank you for creating a repository for recreating the issue! It makes life so much easier, and it's so rarely done. I really appreciate it. So, as you've observed, the problem is caused by the fact that OJ serialises Regexp differently to standard JSON.
I've had this problem before with ActiveSupport, and had to resort to some dodgey dodgey hacks to make it work. I'll see if I can do the same to make it work with OJ. |
@ohler55 make some branch where he tries to fix it on |
Any update on this one? Can I help you somehow? |
I think it was resolved. Oj was using the default for Rails instead of for the JSON gem. Now it does both according to the mode. |
Sorry, I got confused and thought the other issue that got closed (#169) was this one. Is it still an issue? |
I guess I jumped the gun. One issue solved but I think there is another one in that |
I still have a the same problem. Test passes as long as I don't use |
@bethesque can you explain? Is it in the Pact code? |
I'm so sorry, I forgot about this. The problem is occurring at this line of code, where the incoming JSON should be loaded into Ruby classes.
The relevant part of the JSON is: [{"json_class":"Pact::SomethingLike","contents":"gator"}] Without OJA
With OJThe hash stays as a hash, and does not get loaded into a
I'm guessing OJ uses a different technique for recognising and loading embedded Ruby classes in JSON. |
I've narrowed down the problem in this failing test: bethesque/oj-pact-problem@63cfd07 If you run it with 1) Pact::SomethingLike JSON.load creates a SomethingLike object from json
Failure/Error: expect(subject).to eq(SomethingLike.new({"thing" => "blah"}))
expected: #<Pact::SomethingLike:0x007faf5215ecb8 @contents={"thing"=>"blah"}>
got: {"json_class"=>"Pact::SomethingLike", "contents"=>{"thing"=>"blah"}}
(compared using ==)
Diff:
@@ -1,2 +1,3 @@
-#<Pact::SomethingLike:0x007faf5215ecb8 @contents={"thing"=>"blah"}>
+"contents" => {"thing"=>"blah"},
+"json_class" => "Pact::SomethingLike",
# ./spec/models/something_like_spec.rb:23:in `block (3 levels) in <module:Pact>' |
That's helpful. Oj will honor the puts Oj.default_options |
|
It looks ok to me 🤔 |
Oj is in |
I cannot fix the error with any value of |
Can you call |
It doesn't fix it. The only thing that makes it work is taking away the |
That is odd although rails and the JSON do fight over encoding. In then end, the setting that |
Do you have a test setup I can use to put together a set of options that will do what you want? |
Yes, you can clone this: https://github.com/bethesque/oj-pact-problem |
Okay, thanks. Will look into it tomorrow. |
Adding |
Thanks @ohler55. As a summary for future users with the same problem, if you're using Pact with OJ and you call @seban this is a change that I think belongs in your codebase rather than in the Pact code, so I'm going to close this issue now. |
I was nice working with you on this. Thanks. |
Thanks for your help @ohler55 |
@bethesque I am still facing the same issue even after adding I am using if I comment out the initializer it works as expected below is the initializer
Default options on Oj
i don't see after adding |
@bethesque you can ignore my comment as per ohler55/oj#532 |
oj is A fast JSON parser and Object marshaller as a Ruby gem. I tried to used it in my Rails application but looks like pact tests are failing when
oj
is used as default parser/marshaller.I have posted an inssue in
oj
gem already - ohler55/oj#475. Now JSON representation looks ok, but rspec is still failing and it looks like more work than that is required.I created also sample https://github.com/seban/oj-pact-problem rails (4.2.10) app to reproduce conditions.
Can some one advise me on this one?
The text was updated successfully, but these errors were encountered: