File tree Expand file tree Collapse file tree 3 files changed +25
-0
lines changed
Expand file tree Collapse file tree 3 files changed +25
-0
lines changed Original file line number Diff line number Diff line change @@ -273,13 +273,31 @@ func (c Contains) JSONChildren() (res map[string]JSONPather) {
273273 return Schema (c ).JSONChildren ()
274274}
275275
276+ // MarshalJSON implements the json.Marshaler interface for Schema
277+ func (c * Contains ) MarshalJSON () ([]byte , error ) {
278+ switch c .schemaType {
279+ case schemaTypeFalse :
280+ return []byte ("false" ), nil
281+ case schemaTypeTrue :
282+ return []byte ("true" ), nil
283+ default :
284+ obj := map [string ]interface {}{}
285+
286+ for k , v := range c .keywords {
287+ obj [k ] = v
288+ }
289+ return json .Marshal (obj )
290+ }
291+ }
292+
276293// UnmarshalJSON implements the json.Unmarshaler interface for Contains
277294func (c * Contains ) UnmarshalJSON (data []byte ) error {
278295 var sch Schema
279296 if err := json .Unmarshal (data , & sch ); err != nil {
280297 return err
281298 }
282299 * c = Contains (sch )
300+
283301 return nil
284302}
285303
Original file line number Diff line number Diff line change @@ -617,6 +617,7 @@ func TestJSONCoding(t *testing.T) {
617617 "testdata/coding/numeric.json" ,
618618 "testdata/coding/objects.json" ,
619619 "testdata/coding/strings.json" ,
620+ "testdata/coding/contains.json" ,
620621 }
621622
622623 for i , c := range cases {
Original file line number Diff line number Diff line change 1+ {
2+ "contains" : {
3+ "const" : " foobar"
4+ },
5+ "type" : " array"
6+ }
You can’t perform that action at this time.
0 commit comments