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

Implement to_json(json : JSON::Builder) on BigDecimal #7856

Closed
petr-fischer opened this issue Jun 4, 2019 · 1 comment · Fixed by #9898
Closed

Implement to_json(json : JSON::Builder) on BigDecimal #7856

petr-fischer opened this issue Jun 4, 2019 · 1 comment · Fixed by #9898
Labels
help wanted This issue is generally accepted and needs someone to pick it up kind:feature topic:stdlib

Comments

@petr-fischer
Copy link

Implement method to_json(json : JSON::Builder) on BigDecimal class. BigInt and BigFloat are OK. to_yaml(...) is properly defined in the file "yaml/to_yaml.cr" on the Number superclass, to_json can be probably defined on the Number class too (in the file "json/to_json.cr").

@jhass jhass added help wanted This issue is generally accepted and needs someone to pick it up kind:feature topic:stdlib labels Jun 5, 2019
@petr-fischer
Copy link
Author

petr-fischer commented Jun 7, 2019

Simple dirty fix is to add this code:

struct BigDecimal
  def to_json(json : JSON::Builder)
    json.raw(self.to_s)
  end 
end

to the big/json.cr. But I personally don't like it, because YAML treatment of BigDecimal is probably more "elaborated".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted This issue is generally accepted and needs someone to pick it up kind:feature topic:stdlib
Projects
None yet
2 participants