Skip to content

Fix: JSONSlice stores "null" string instead of SQL NULL when nil#322

Merged
jinzhu merged 2 commits into
go-gorm:masterfrom
dannyota:fix-jsonslice-nil
May 11, 2026
Merged

Fix: JSONSlice stores "null" string instead of SQL NULL when nil#322
jinzhu merged 2 commits into
go-gorm:masterfrom
dannyota:fix-jsonslice-nil

Conversation

@dannyota
Copy link
Copy Markdown
Contributor

@dannyota dannyota commented Feb 6, 2026

  • Do only one thing
  • Non breaking API changes
  • Tested

What did this pull request do?

Add nil checks to JSONSlice Value(), Scan(), and GormValue() — same pattern already used by JSON (json.go:25) and JSONMap (json_map.go:23) but missing from JSONSlice.

Without this fix, a nil JSONSlice stores the literal string "null" instead of SQL NULL.

User Case Description

Same issue as #99 but for JSONSlice[T].

Fixes #314

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@jinzhu
Copy link
Copy Markdown
Member

jinzhu commented May 11, 2026

Hi @dannyota

Can you add some tests?

Add a nil JSONSlice case to TestJSONSlice (persisted as SQL NULL,
scans back as nil) and a nil Value() check to TestJSONTypeValueTypes,
matching the existing JSONMap nil coverage.
@jinzhu jinzhu merged commit c38d480 into go-gorm:master May 11, 2026
27 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Same "null" value problem like in #99

2 participants