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

Add JSON serialization to big number types #9898

Merged

Conversation

dukenguyenxyz
Copy link
Contributor

@dukenguyenxyz dukenguyenxyz commented Nov 9, 2020

This PR:

Summary of Changes:

  • Allow serialisation: and .to_json to all Big* structs (BigInt,BigFloat, BigDecimal)

  • Serialisation Big*.to_json is enabled through adding JSON::Builder.number methods for each Big* type, serialising into Number types

  • Allow deserialisation of BigFloat from Int or Float

  • Allow all Big* structs to be used as JSON keys: add .to_json_object_key

  • Add missing pending_win32 "does for BigDecimal" to yaml/serialization_spec.cr

Further Discussion:

spec/std/json/serialization_spec.cr Outdated Show resolved Hide resolved
src/json/builder.cr Outdated Show resolved Hide resolved
@straight-shoota straight-shoota changed the title Add serialization to big Add JSON serialization to big number types Dec 8, 2020
@straight-shoota straight-shoota merged commit 2588d46 into crystal-lang:master Dec 8, 2020
@straight-shoota
Copy link
Member

Thank you @dukeraphaelng

@straight-shoota
Copy link
Member

Seems now we're just missing the same thing for YAML...

src/big/json.cr Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement to_json(json : JSON::Builder) on BigDecimal
4 participants