Closed nigeltao closed 2 months ago
Decoder.ReadValue
gives guarantee of what the implementation does (i.e., it strips whitespace).
Value
just documents that surrounding whitespace is permissible (e.g., if you want to call Encoder.WriteValue
with surrounding whitespace).
For an UnmarshalJSON
method, the implementation cannot safely assume that it is stripped of whitespace. When called by the "json" package it will always be, but nothing stops users from directly calling UnmarshalJSON
.
Closing as the documentation says:
Value may contain leading and/or trailing whitespace.
https://github.com/go-json-experiment/json/blob/8aa127fd5801b9db7792f3467d6a426a8f83b875/jsontext/value.go#L29
says "Value may contain leading and/or trailing whitespace". But also,
https://github.com/go-json-experiment/json/blob/8aa127fd5801b9db7792f3467d6a426a8f83b875/jsontext/decode.go#L576-L577
says that
Decoder.ReadValue
"returns the next raw JSON value... stripped of any leading or trailing whitespace".If I'm processing a
Value
, do I need to handle whitespace? IsDecoder.ReadValue
basically the only blessed way to createValue
values?