Update filter to use json package interfaces.
This commit is contained in:
+2
-2
@@ -111,7 +111,7 @@ func WithExtension(l string, e json.RawMessage) FilterOption {
|
|||||||
|
|
||||||
// MarshalJSON converts the filter to JSON with standard fields, tag filters
|
// MarshalJSON converts the filter to JSON with standard fields, tag filters
|
||||||
// (prefixed with "#"), and extensions merged into a single object.
|
// (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{})
|
outputMap := make(map[string]interface{})
|
||||||
|
|
||||||
// Add standard fields
|
// Add standard fields
|
||||||
@@ -168,7 +168,7 @@ func MarshalJSON(f Filter) ([]byte, error) {
|
|||||||
|
|
||||||
// UnmarshalJSON parses JSON into the filter, separating standard fields,
|
// UnmarshalJSON parses JSON into the filter, separating standard fields,
|
||||||
// tag filters (keys starting with "#"), and extensions.
|
// 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
|
// Decode into raw map
|
||||||
raw := make(FilterExtensions)
|
raw := make(FilterExtensions)
|
||||||
if err := json.Unmarshal(data, &raw); err != nil {
|
if err := json.Unmarshal(data, &raw); err != nil {
|
||||||
|
|||||||
@@ -547,7 +547,7 @@ var roundTripTestCases = []FilterRoundTripTestCase{
|
|||||||
func TestFilterMarshalJSON(t *testing.T) {
|
func TestFilterMarshalJSON(t *testing.T) {
|
||||||
for _, tc := range marshalTestCases {
|
for _, tc := range marshalTestCases {
|
||||||
t.Run(tc.name, func(t *testing.T) {
|
t.Run(tc.name, func(t *testing.T) {
|
||||||
result, err := MarshalJSON(tc.filter)
|
result, err := json.Marshal(tc.filter)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
var expectedMap, actualMap map[string]interface{}
|
var expectedMap, actualMap map[string]interface{}
|
||||||
@@ -565,7 +565,7 @@ func TestFilterUnmarshalJSON(t *testing.T) {
|
|||||||
for _, tc := range unmarshalTestCases {
|
for _, tc := range unmarshalTestCases {
|
||||||
t.Run(tc.name, func(t *testing.T) {
|
t.Run(tc.name, func(t *testing.T) {
|
||||||
var result Filter
|
var result Filter
|
||||||
err := UnmarshalJSON([]byte(tc.input), &result)
|
err := json.Unmarshal([]byte(tc.input), &result)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
expectEqualFilters(t, result, tc.expected)
|
expectEqualFilters(t, result, tc.expected)
|
||||||
@@ -576,11 +576,11 @@ func TestFilterUnmarshalJSON(t *testing.T) {
|
|||||||
func TestFilterRoundTrip(t *testing.T) {
|
func TestFilterRoundTrip(t *testing.T) {
|
||||||
for _, tc := range roundTripTestCases {
|
for _, tc := range roundTripTestCases {
|
||||||
t.Run(tc.name, func(t *testing.T) {
|
t.Run(tc.name, func(t *testing.T) {
|
||||||
jsonBytes, err := MarshalJSON(tc.filter)
|
jsonBytes, err := json.Marshal(tc.filter)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
var result Filter
|
var result Filter
|
||||||
err = UnmarshalJSON(jsonBytes, &result)
|
err = json.Unmarshal(jsonBytes, &result)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
expectEqualFilters(t, result, tc.filter)
|
expectEqualFilters(t, result, tc.filter)
|
||||||
|
|||||||
Reference in New Issue
Block a user