Open deydebaditya opened 3 weeks ago
Hey @deydebaditya can we work onto closing this PR? Just a one linter change is required as discussed above and we are good to go! Thanks
Will work on it by tomorrow. Would need to change a bit if implementation in the method body as well, since I’m serializing the json bytes back into the map reference at the end. Like I said before, maps are reference types as in the values to map keys are references definitely, but the actual map object would still be passed by value in this method. Will make the relevant changes.
On Tue, 12 Nov 2024 at 9:17 PM, Ashwin Kulkarni @.***> wrote:
Hey @deydebaditya https://github.com/deydebaditya can we work onto closing this PR? Just a one linter change is required as discussed above and we are good to go! Thanks
— Reply to this email directly, view it on GitHub https://github.com/DiceDB/dice/pull/1227#issuecomment-2470887049, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACX7SWUKY425P3USK5XH33D2AIPHZAVCNFSM6AAAAABQ7TMNSKVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDINZQHA4DOMBUHE . You are receiving this because you were mentioned.Message ID: @.***>
Change description
When working with
map[string]interface{}
in Go,json.Marshal
will automatically infer the data type for each element based on theinterface{}
type that we use. However, in our case,json.Marshal
is casting values incorrectly (e.g., casting integer values to float64), it may be due to Go’s internal handling of untyped constants and generic types withininterface{}
To fix this, I've added an explicit check during unmarshalling of the JSON body in the request payload for
int64
types. I've also added a recursive unmarshalling to check for any such big integer values in nested JSON fields as well.To ensure that
json.Marshal
preserves the original data types, I've enforced specific types in our map by usingjson.Number
for numeric data types before marshaling again.Lastly, instead of using a vanilla json.Unmarshal() at the end of the request map creation, the JSON decoder needs to be aware that it explicitly needs to use numbers, instead of using Go's default handling of the
interface{}
type.Working
Request
Data set in DICE DB
Response from HTTP server