This commit is contained in:
parent
9955eacf96
commit
b0e443ad99
@ -3,6 +3,7 @@ package dataext
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"gogs.mikescher.com/BlackForestBytes/goext/langext"
|
||||
)
|
||||
|
||||
type JsonTwoWayMarshal interface {
|
||||
@ -10,7 +11,11 @@ type JsonTwoWayMarshal interface {
|
||||
json.Unmarshaler
|
||||
}
|
||||
|
||||
type JsonOpt[T JsonTwoWayMarshal] struct {
|
||||
type JsonOptType interface {
|
||||
JsonTwoWayMarshal | ~string | ~bool | langext.NumberConstraint
|
||||
}
|
||||
|
||||
type JsonOpt[T JsonOptType] struct {
|
||||
isSet bool
|
||||
value T
|
||||
}
|
||||
@ -25,7 +30,7 @@ func (m JsonOpt[T]) MarshalJSON() ([]byte, error) {
|
||||
return []byte("null"), nil
|
||||
}
|
||||
|
||||
return m.MarshalJSON()
|
||||
return json.Marshal(m.value)
|
||||
}
|
||||
|
||||
// UnmarshalJSON sets *m to a copy of data.
|
||||
@ -34,7 +39,7 @@ func (m *JsonOpt[T]) UnmarshalJSON(data []byte) error {
|
||||
return errors.New("JsonOpt: UnmarshalJSON on nil pointer")
|
||||
}
|
||||
|
||||
return m.value.UnmarshalJSON(data)
|
||||
return json.Unmarshal(data, &m.value)
|
||||
}
|
||||
|
||||
func (m JsonOpt[T]) IsSet() bool {
|
||||
|
@ -1,5 +1,5 @@
|
||||
package goext
|
||||
|
||||
const GoextVersion = "0.0.419"
|
||||
const GoextVersion = "0.0.420"
|
||||
|
||||
const GoextVersionTimestamp = "2024-03-23T17:49:56+0100"
|
||||
const GoextVersionTimestamp = "2024-03-23T18:01:41+0100"
|
||||
|
Loading…
Reference in New Issue
Block a user