diff options
| author | mhsanaei <ho3ein.sanaei@gmail.com> | 2025-09-20 10:35:50 +0300 |
|---|---|---|
| committer | mhsanaei <ho3ein.sanaei@gmail.com> | 2025-09-20 10:35:50 +0300 |
| commit | 6ced549deaecb42b9bb93ea9efcb4c1bbaabe8a4 (patch) | |
| tree | 28d8d82530476cf607e4d05ca189ae05868711e6 /util/json_util/json.go | |
| parent | f60682a6b7cb749fee403c84e2587c3ad7e7ced0 (diff) | |
docs: add comments for all functions
Diffstat (limited to 'util/json_util/json.go')
| -rw-r--r-- | util/json_util/json.go | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/util/json_util/json.go b/util/json_util/json.go index 54e3728a..d2d391bf 100644 --- a/util/json_util/json.go +++ b/util/json_util/json.go @@ -1,12 +1,15 @@ +// Package json_util provides JSON utilities including a custom RawMessage type. package json_util import ( "errors" ) +// RawMessage is a custom JSON raw message type that marshals empty slices as "null". type RawMessage []byte -// MarshalJSON: Customize json.RawMessage default behavior +// MarshalJSON customizes the JSON marshaling behavior for RawMessage. +// Empty RawMessage values are marshaled as "null" instead of "[]". func (m RawMessage) MarshalJSON() ([]byte, error) { if len(m) == 0 { return []byte("null"), nil @@ -14,7 +17,7 @@ func (m RawMessage) MarshalJSON() ([]byte, error) { return m, nil } -// UnmarshalJSON: sets *m to a copy of data. +// UnmarshalJSON sets *m to a copy of the JSON data. func (m *RawMessage) UnmarshalJSON(data []byte) error { if m == nil { return errors.New("json.RawMessage: UnmarshalJSON on nil pointer") |
