@@ -45,7 +45,10 @@ func (t JsonType) Compare(ctx context.Context, a interface{}, b interface{}) (in
4545 return CompareJSON (ctx , a , b )
4646}
4747
48- func convertJSONValue (v interface {}) (interface {}, sql.ConvertInRange , error ) {
48+ // convertJSONValue parses JSON-encoded data if the input is a string or []byte, returning the resulting Go value. For
49+ // other types, the value is returned as-is. The returned value is the raw, unwrapped JSON representation and is later
50+ // wrapped in a JSONDocument by JsonType.Convert.
51+ func convertJSONValue (v interface {}) (val interface {}, inRange sql.ConvertInRange , err error ) {
4952 var data []byte
5053 var charsetMaxLength int64 = 1
5154 switch x := v .(type ) {
@@ -55,19 +58,18 @@ func convertJSONValue(v interface{}) (interface{}, sql.ConvertInRange, error) {
5558 data = []byte (x )
5659 charsetMaxLength = sql .Collation_Default .CharacterSet ().MaxLength ()
5760 default :
58- return nil , sql .OutOfRange , sql . ErrInvalidJson . New ( "unsupported JSON input type" )
61+ return v , sql .InRange , nil
5962 }
6063
6164 if int64 (len (data ))* charsetMaxLength > MaxJsonFieldByteLength {
6265 return nil , sql .InRange , ErrLengthTooLarge .New (len (data ), MaxJsonFieldByteLength )
6366 }
6467
65- var doc interface {}
66- if err := json .Unmarshal (data , & doc ); err != nil {
68+ if err := json .Unmarshal (data , & val ); err != nil {
6769 return nil , sql .OutOfRange , sql .ErrInvalidJson .New (err .Error ())
6870 }
6971
70- return doc , sql .InRange , nil
72+ return val , sql .InRange , nil
7173}
7274
7375// Convert implements Type interface.
0 commit comments