Skip to content

Commit 34898e1

Browse files
Copilotjinzhu
andcommitted
Rollback json.go and json_map.go changes - all JSON types now return string
Co-authored-by: jinzhu <[email protected]>
1 parent d1e3854 commit 34898e1

File tree

4 files changed

+8
-13
lines changed

4 files changed

+8
-13
lines changed

json.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ func (j JSON) Value() (driver.Value, error) {
2525
if len(j) == 0 {
2626
return nil, nil
2727
}
28-
return json.RawMessage(j), nil
28+
return string(j), nil
2929
}
3030

3131
// Scan scan value into Jsonb, implements sql.Scanner interface

json_map.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,7 @@ func (m JSONMap) Value() (driver.Value, error) {
2424
return nil, nil
2525
}
2626
ba, err := m.MarshalJSON()
27-
if err != nil {
28-
return nil, err
29-
}
30-
return json.RawMessage(ba), nil
27+
return string(ba), err
3128
}
3229

3330
// Scan scan value into Jsonb, implements sql.Scanner interface

json_map_test.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -183,17 +183,16 @@ func TestJSONMap_Scan(t *testing.T) {
183183
AssertEqual(t, obj["user_id"], 1085238870184050699)
184184
}
185185

186-
// TestJSONMapValueType tests that JSONMap returns json.RawMessage from Value() method
187-
// This is required for MySQL driver interpolateParams=true compatibility to avoid error 3144
186+
// TestJSONMapValueType tests the return type from JSONMap Value() method
188187
func TestJSONMapValueType(t *testing.T) {
189188
// Test JSONMap
190189
jsonMap := datatypes.JSONMap{"key": "value", "number": 42}
191190
value, err := jsonMap.Value()
192191
if err != nil {
193192
t.Errorf("JSONMap.Value() error: %v", err)
194193
}
195-
if _, ok := value.(json.RawMessage); !ok {
196-
t.Errorf("JSONMap.Value() should return json.RawMessage, got %T", value)
194+
if _, ok := value.(string); !ok {
195+
t.Errorf("JSONMap.Value() should return string, got %T", value)
197196
}
198197

199198
// Test empty JSONMap

json_test.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -526,17 +526,16 @@ func TestJSONArrayQuery(t *testing.T) {
526526
}
527527
}
528528

529-
// TestJSONValueTypes tests that all JSON types return json.RawMessage from Value() method
530-
// This is required for MySQL driver interpolateParams=true compatibility to avoid error 3144
529+
// TestJSONValueTypes tests the return types from JSON Value() methods
531530
func TestJSONValueTypes(t *testing.T) {
532531
// Test JSON type
533532
jsonData := datatypes.JSON(`{"test": "value"}`)
534533
value, err := jsonData.Value()
535534
if err != nil {
536535
t.Errorf("JSON.Value() error: %v", err)
537536
}
538-
if _, ok := value.(json.RawMessage); !ok {
539-
t.Errorf("JSON.Value() should return json.RawMessage, got %T", value)
537+
if _, ok := value.(string); !ok {
538+
t.Errorf("JSON.Value() should return string, got %T", value)
540539
}
541540

542541
// Test empty JSON

0 commit comments

Comments
 (0)