This commit is contained in:
parent
9955eacf96
commit
b0e443ad99
@ -3,6 +3,7 @@ package dataext
|
|||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
|
"gogs.mikescher.com/BlackForestBytes/goext/langext"
|
||||||
)
|
)
|
||||||
|
|
||||||
type JsonTwoWayMarshal interface {
|
type JsonTwoWayMarshal interface {
|
||||||
@ -10,7 +11,11 @@ type JsonTwoWayMarshal interface {
|
|||||||
json.Unmarshaler
|
json.Unmarshaler
|
||||||
}
|
}
|
||||||
|
|
||||||
type JsonOpt[T JsonTwoWayMarshal] struct {
|
type JsonOptType interface {
|
||||||
|
JsonTwoWayMarshal | ~string | ~bool | langext.NumberConstraint
|
||||||
|
}
|
||||||
|
|
||||||
|
type JsonOpt[T JsonOptType] struct {
|
||||||
isSet bool
|
isSet bool
|
||||||
value T
|
value T
|
||||||
}
|
}
|
||||||
@ -25,7 +30,7 @@ func (m JsonOpt[T]) MarshalJSON() ([]byte, error) {
|
|||||||
return []byte("null"), nil
|
return []byte("null"), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
return m.MarshalJSON()
|
return json.Marshal(m.value)
|
||||||
}
|
}
|
||||||
|
|
||||||
// UnmarshalJSON sets *m to a copy of data.
|
// 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 errors.New("JsonOpt: UnmarshalJSON on nil pointer")
|
||||||
}
|
}
|
||||||
|
|
||||||
return m.value.UnmarshalJSON(data)
|
return json.Unmarshal(data, &m.value)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m JsonOpt[T]) IsSet() bool {
|
func (m JsonOpt[T]) IsSet() bool {
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
package goext
|
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