Update filter to use json package interfaces.

This commit is contained in:
Jay
2026-05-08 09:54:31 -04:00
parent 047fc9d9a1
commit 60c8e8256b
2 changed files with 6 additions and 6 deletions
+2 -2
View File
@@ -111,7 +111,7 @@ func WithExtension(l string, e json.RawMessage) FilterOption {
// MarshalJSON converts the filter to JSON with standard fields, tag filters
// (prefixed with "#"), and extensions merged into a single object.
func MarshalJSON(f Filter) ([]byte, error) {
func (f Filter) MarshalJSON() ([]byte, error) {
outputMap := make(map[string]interface{})
// Add standard fields
@@ -168,7 +168,7 @@ func MarshalJSON(f Filter) ([]byte, error) {
// UnmarshalJSON parses JSON into the filter, separating standard fields,
// tag filters (keys starting with "#"), and extensions.
func UnmarshalJSON(data []byte, f *Filter) error {
func (f *Filter) UnmarshalJSON(data []byte) error {
// Decode into raw map
raw := make(FilterExtensions)
if err := json.Unmarshal(data, &raw); err != nil {
+4 -4
View File
@@ -547,7 +547,7 @@ var roundTripTestCases = []FilterRoundTripTestCase{
func TestFilterMarshalJSON(t *testing.T) {
for _, tc := range marshalTestCases {
t.Run(tc.name, func(t *testing.T) {
result, err := MarshalJSON(tc.filter)
result, err := json.Marshal(tc.filter)
assert.NoError(t, err)
var expectedMap, actualMap map[string]interface{}
@@ -565,7 +565,7 @@ func TestFilterUnmarshalJSON(t *testing.T) {
for _, tc := range unmarshalTestCases {
t.Run(tc.name, func(t *testing.T) {
var result Filter
err := UnmarshalJSON([]byte(tc.input), &result)
err := json.Unmarshal([]byte(tc.input), &result)
assert.NoError(t, err)
expectEqualFilters(t, result, tc.expected)
@@ -576,11 +576,11 @@ func TestFilterUnmarshalJSON(t *testing.T) {
func TestFilterRoundTrip(t *testing.T) {
for _, tc := range roundTripTestCases {
t.Run(tc.name, func(t *testing.T) {
jsonBytes, err := MarshalJSON(tc.filter)
jsonBytes, err := json.Marshal(tc.filter)
assert.NoError(t, err)
var result Filter
err = UnmarshalJSON(jsonBytes, &result)
err = json.Unmarshal(jsonBytes, &result)
assert.NoError(t, err)
expectEqualFilters(t, result, tc.filter)