1- // Copyright © 2023 Kaleido, Inc.
1+ // Copyright © 2024 Kaleido, Inc.
22//
33// SPDX-License-Identifier: Apache-2.0
44//
@@ -21,7 +21,7 @@ import (
2121 "crypto/sha256"
2222 "database/sql/driver"
2323 "encoding/json"
24- "math/big "
24+ "strings "
2525
2626 "github.com/hyperledger/firefly-common/pkg/i18n"
2727 "github.com/hyperledger/firefly-common/pkg/log"
@@ -78,37 +78,13 @@ func (h *JSONAny) Unmarshal(ctx context.Context, v interface{}) error {
7878 return i18n .NewError (ctx , i18n .MsgNilOrNullObject )
7979 }
8080
81- err := json .Unmarshal ([]byte (* h ), v )
82- if err != nil {
81+ d := json .NewDecoder (strings .NewReader (h .String ()))
82+ d .UseNumber ()
83+ if err := d .Decode (v ); err != nil {
8384 return err
8485 }
8586
86- // To support large numbers, check if Go unmarshalled the data to a float64 and then
87- // unmarshal it to a string instead
88- if vt , ok := v .(* interface {}); ok {
89- if _ , ok := (* vt ).(float64 ); ok {
90- // If the value has unmarshalled to a float64 we can't be sure the number
91- // didn't overflow 2^64-1 so we'll use parseFloat on the original value
92- // and return the string representation of the number.
93- i := new (big.Int )
94- f , _ , err := big .ParseFloat (h .String (), 10 , 256 , big .ToNearestEven )
95- if err != nil {
96- return err
97- }
98- i , accuracy := f .Int (i )
99- if accuracy != big .Exact {
100- // If we weren't able to decode without losing precision, return an error
101- return i18n .NewError (ctx , i18n .MsgBigIntParseFailed )
102- }
103-
104- err = json .Unmarshal ([]byte ("\" " + i .String ()+ "\" " ), v )
105- if err != nil {
106- return err
107- }
108- }
109- }
110-
111- return err
87+ return nil
11288}
11389
11490func (h * JSONAny ) Hash () * Bytes32 {
0 commit comments