You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is your feature request related to a problem? Please describe.
encoding/json's behavior when decoding arbitrary numbers to any is either float64, or json.Number, depending on decoder configuration.
fxamacker/cbor already has pretty good method-signature compatibility with encoding/json, but in the case of untyped decoding, requires additional complexity on the calling code in the form of additional types which must be handled: int64, uint64, and *big.Int.
Describe the solution you'd like
Add an IntDecMode value to cause all CBOR integers (including *big.Int) to be decoded as float64 when the destination is *any. This would, of course, be lossy for values far from zero.
Add an IntDecMode value to cause all CBOR integers (including *big.Int) to be decoded as json.Number. This would not be especially efficient, but would provide excellent compatibility with encoding/json for existing applications needing arbitrary-precision number support. Internally, this could just use behave like IntDecConvertNone with a post-process call to strconv.FormatInt, strconv.FormatUint, or (*big.Int).String, depending on the underlying type; or some specialized binary-to-decimal converter.
Optional: JSONCompatDecOptions and JSONNumberDecOptions (or similar) functions, which set these options, as well as setting DefaultMapType to map[string]any.
The text was updated successfully, but these errors were encountered:
Is your feature request related to a problem? Please describe.
encoding/json
's behavior when decoding arbitrary numbers toany
is eitherfloat64
, orjson.Number
, depending on decoder configuration.fxamacker/cbor
already has pretty good method-signature compatibility withencoding/json
, but in the case of untyped decoding, requires additional complexity on the calling code in the form of additional types which must be handled:int64
,uint64
, and*big.Int
.Describe the solution you'd like
IntDecMode
value to cause all CBOR integers (including*big.Int
) to be decoded asfloat64
when the destination is*any
. This would, of course, be lossy for values far from zero.IntDecMode
value to cause all CBOR integers (including*big.Int
) to be decoded asjson.Number
. This would not be especially efficient, but would provide excellent compatibility withencoding/json
for existing applications needing arbitrary-precision number support. Internally, this could just use behave likeIntDecConvertNone
with a post-process call tostrconv.FormatInt
,strconv.FormatUint
, or(*big.Int).String
, depending on the underlying type; or some specialized binary-to-decimal converter.JSONCompatDecOptions
andJSONNumberDecOptions
(or similar) functions, which set these options, as well as settingDefaultMapType
tomap[string]any
.The text was updated successfully, but these errors were encountered: