I have a ruby class with the following definition:
class MyResponse
attr_writer :status, :message
def initialize(status,message)
@status = status
@message = message
end
end
When I try to do a to_json on the object of type MyResponse, I am properly getting the json converted string.
The problem is, with the same set of parameters passed to MyResponse, I’m getting empty string sometimes.
Ex:
response = MyRespons.new("Abcd", 0)
puts response.to_json gives:
"{\"status\": \"Abcd\", \"message\": 0}"
The same sometimes gives:
"\"#<MyResponse:0xb687d884>\""
My question is how do i catch the json errors? Because, in the second case, there is absolutely no difference in the parameters passed to MyResponse class.
The behaviour is random.
Update: I found a similar question. But the answer is to update the gem. I cannot update my current gem.
Rails: to_json method not working as expected
All right, turns out that the json gem had an issue. I now am using an alias to the original to_json which seems to be working fine.