github.com/cloudfoundry/cli@v7.1.0+incompatible/types/filtered_interface.go (about) 1 package types 2 3 import ( 4 "encoding/json" 5 ) 6 7 type FilteredInterface struct { 8 IsSet bool 9 Value interface{} 10 } 11 12 func (n *FilteredInterface) UnmarshalJSON(rawJSON []byte) error { 13 var value interface{} 14 err := json.Unmarshal(rawJSON, &value) 15 if err != nil { 16 return err 17 } 18 19 n.Value = value 20 n.IsSet = true 21 return nil 22 } 23 24 func (n FilteredInterface) MarshalJSON() ([]byte, error) { 25 if n.IsSet { 26 return json.Marshal(n.Value) 27 } 28 29 return json.Marshal(new(json.RawMessage)) 30 }