v0.0.420
Some checks failed
Build Docker and Deploy / Run goext test-suite (push) Failing after 36s

This commit is contained in:
Mike Schwörer 2024-03-23 18:01:41 +01:00
parent 9955eacf96
commit b0e443ad99
Signed by: Mikescher
GPG Key ID: D3C7172E0A70F8CF
2 changed files with 10 additions and 5 deletions

View File

@ -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 {

View File

@ -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"