Closed Jarema closed 1 month ago
the PR is attempting to avoid this unmarshal here
Ah gotcha! Thanks and apologies did not look at the complete function for isEmptyRequest.
Let's address @aricart comment then should be good to go. Thanks @Jarema !
There is json.Valid([]byte)
in the stdlib, that would be lighter than the call to json.Unmarshal
: https://pkg.go.dev/encoding/json#Valid
Should we use that instead @Jarema and just change isEmptyRequest?
The code isn’t checking if it’s valid json. It’s checking if the request - even if valid - is an empty object.
As @ripienaar mentioned - json.Unmarshal
in isEmptyRequest
does not check just for validity.
Until now, in JS API we were checking if request payload is empty. That check was unmarshaling that payload before we did second unmarshal for the destination type. This commit adds separate check to avoid double unmarshaling.
This PR does not change
isEmptyRequest
implementation, as its a less strict check.Signed-off-by: Tomasz Pietrek tomasz@nats.io