Skip to content

json.RawMessage behavior differs from byte slice #350

@lefinal

Description

@lefinal

Describe the bug

json.RawMessage currently gets encoded as byte list when using as value.
An example is provided below, where the content of a field with type json.RawMessage is used. The expected output would be correct JSON as with []byte.

To Reproduce

type MyType struct {
	ContentWithJSONRawMessage json.RawMessage
	ContentWithByteSlice      []byte
}

func main() {
	content := []byte(`{"hello":"world"}`)
	s := MyType{
		ContentWithJSONRawMessage: content,
		ContentWithByteSlice:      content,
	}
	q, _, err := goqu.Insert(goqu.T("my_table")).Rows(goqu.Record{
		"content_with_json_raw_message": s.ContentWithJSONRawMessage,
		"content_with_byte_slice":       s.ContentWithByteSlice,
	}).ToSQL()
	if err != nil {
		panic(err)
	}
	fmt.Println(q)
}

Output:

INSERT INTO "my_table" ("content_with_byte_slice", "content_with_json_raw_message") VALUES ('{"hello":"world"}', (123, 34, 104, 101, 108, 108, 111, 34, 58, 34, 119, 111, 114, 108, 100, 34, 125))

Expected behavior

Both values should be correct JSON as with []byte.

Dialect:

  • postgres
  • mysql
  • sqlite3

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions