diff --git a/v2/object/json.go b/v2/object/json.go index 940aa7c..e2caede 100644 --- a/v2/object/json.go +++ b/v2/object/json.go @@ -124,3 +124,23 @@ func (o *Object) UnmarshalJSON(data []byte) error { return nil } + +func (f *SearchFilter) MarshalJSON() ([]byte, error) { + return protojson.MarshalOptions{ + EmitUnpopulated: true, + }.Marshal( + SearchFilterToGRPCMessage(f), + ) +} + +func (f *SearchFilter) UnmarshalJSON(data []byte) error { + msg := new(object.SearchRequest_Body_Filter) + + if err := protojson.Unmarshal(data, msg); err != nil { + return err + } + + *f = *SearchFilterFromGRPCMessage(msg) + + return nil +} diff --git a/v2/object/json_test.go b/v2/object/json_test.go index ceefd96..e8ad5d2 100644 --- a/v2/object/json_test.go +++ b/v2/object/json_test.go @@ -78,3 +78,15 @@ func TestObjectJSON(t *testing.T) { require.Equal(t, o, o2) } + +func TestSearchFilterJSON(t *testing.T) { + f := generateFilter("key", "value") + + data, err := f.MarshalJSON() + require.NoError(t, err) + + f2 := new(object.SearchFilter) + require.NoError(t, f2.UnmarshalJSON(data)) + + require.Equal(t, f, f2) +}