github.com/DaAlbrecht/cf-cli@v0.0.0-20231128151943-1fe19bb400b9/types/optional_boolean.go (about) 1 package types 2 3 import ( 4 "encoding/json" 5 ) 6 7 type OptionalBoolean struct { 8 IsSet bool 9 Value bool 10 } 11 12 func NewOptionalBoolean(value bool) OptionalBoolean { 13 return OptionalBoolean{ 14 IsSet: true, 15 Value: value, 16 } 17 } 18 19 func (o *OptionalBoolean) UnmarshalJSON(rawJSON []byte) error { 20 if err := json.Unmarshal(rawJSON, &o.Value); err != nil { 21 return err 22 } 23 24 o.IsSet = true 25 return nil 26 } 27 28 func (o OptionalBoolean) MarshalJSON() ([]byte, error) { 29 return json.Marshal(o.Value) 30 } 31 32 func (o OptionalBoolean) OmitJSONry() bool { 33 return !o.IsSet 34 }