|
|
|
@ -27,13 +27,6 @@ type JsonBox[T any] struct {
|
|
|
|
|
data T
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (j *JsonBox[T]) MarshalJSON() ([]byte, error) {
|
|
|
|
|
if j == nil {
|
|
|
|
|
return []byte(`null`), nil
|
|
|
|
|
}
|
|
|
|
|
return json.Marshal(j.data)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (j *JsonBox[T]) Box(t T) {
|
|
|
|
|
j.data = t
|
|
|
|
|
}
|
|
|
|
@ -42,6 +35,13 @@ func (j *JsonBox[T]) Unbox() T {
|
|
|
|
|
return j.data
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (j *JsonBox[T]) MarshalJSON() ([]byte, error) {
|
|
|
|
|
if j == nil {
|
|
|
|
|
return []byte(`null`), nil
|
|
|
|
|
}
|
|
|
|
|
return json.Marshal(j.data)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (j *JsonBox[T]) UnmarshalJSON(data []byte) error {
|
|
|
|
|
if j == nil {
|
|
|
|
|
return errors.New("JsonBox.UnmarshalJSON: on nil pointer")
|
|
|
|
|