Skip to content
This repository was archived by the owner on Apr 1, 2025. It is now read-only.

Add support for json.Number.#414

Merged
niemeyer merged 2 commits intogo-yaml:v2from
sensu:json.Number
Nov 15, 2018
Merged

Add support for json.Number.#414
niemeyer merged 2 commits intogo-yaml:v2from
sensu:json.Number

Conversation

@echlebek
Copy link
Copy Markdown

@echlebek echlebek commented Nov 5, 2018

This commit adds support for encoding json.Number as a number
instead of as a string, which is the underlying type of
json.Number.

Care has been taken to not introduce a dependency on the
encoding/json package, by using an interface that specifies the
methods of json.Number instead of the datatype itself. This also
means that other packages that use a similar datatype will be
supported. (Like json-iterator)

This is useful for tools that wish to convert JSON data into YAML
data by deserializing JSON into a map[string]interface{}, and use
the json.Encoder's UseNumber() method, or structs that use the
json.Number datatype and also wish to support yaml.

This commit adds support for encoding json.Number as a number
instead of as a string, which is the underlying type of
json.Number.

Care has been taken to not introduce a dependency on the
encoding/json package, by using an interface that specifies the
methods of json.Number instead of the datatype itself. This also
means that other packages that use a similar datatype will be
supported. (Like json-iterator)

This is useful for tools that wish to convert JSON data into YAML
data by deserializing JSON into a map[string]interface{}, and use
the json.Encoder's UseNumber() method, or structs that use the
json.Number datatype and also wish to support yaml.
@echlebek
Copy link
Copy Markdown
Author

echlebek commented Nov 5, 2018

I based this work on v2, since it's the version I'm using, but I'm happy to base it on the devel branch if that would be more appropriate.

@niemeyer niemeyer merged commit 51d6538 into go-yaml:v2 Nov 15, 2018
@niemeyer
Copy link
Copy Markdown
Contributor

Thanks!

@echlebek
Copy link
Copy Markdown
Author

Thank you!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants