Skip to content
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

Object#to_json(io) definition missing #3106

Closed
Sija opened this issue Aug 7, 2016 · 7 comments
Closed

Object#to_json(io) definition missing #3106

Sija opened this issue Aug 7, 2016 · 7 comments

Comments

@Sija
Copy link
Contributor

Sija commented Aug 7, 2016

Hi, I've just encountered below error and noticed there's no Object#to_json(io) counterpart, is it intentional or just an omission?

wrong number of arguments for 'Time#to_json' (given 1, expected 0)
Overloads are:
 - Object#to_json()

https://carc.in/#/r/16d8

@asterite
Copy link
Member

asterite commented Aug 7, 2016

The problem is that Time doesn't define a to_json(io) (there's no standard way to serialize a Time to JSON). But Object#to_json is defined, and it invokes to_json(io). That's why the error is confusing.

@Sija
Copy link
Contributor Author

Sija commented Aug 7, 2016

Maybe sth along the lines of:

class Object
  def to_json(io)
    io << to_s.to_json
  end
end

@jhass
Copy link
Member

jhass commented Aug 7, 2016

I think ISO8601 would be a fair default value for Time#to_json. If somebody needs something else they can specify a converter.

JS seems to default to that too:

JSON.stringify({"foo": (new Date())})
"{"foo":"2016-08-07T07:19:39.733Z"}"

@ysbaddaden
Copy link
Contributor

I'm with @jhass, there isnt any defined format for Time in JSON but there are acceptable ones. ISO8601 looks perfect to me.

@sdogruyol
Copy link
Member

I agree that ISO8601 should be a good default for JSON.

@sdogruyol
Copy link
Member

Why don't we handle this already? @asterite i think this should be trivial to implement.

@sdogruyol
Copy link
Member

@asterite 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants