Skip to content

Commit

Permalink
fix linter errors
Browse files Browse the repository at this point in the history
  • Loading branch information
lovromazgon committed Feb 28, 2024
1 parent d327c8f commit 49ce3f3
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
2 changes: 2 additions & 0 deletions opencdc/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,10 @@ func (d RawData) Clone() Data {
func (d RawData) MarshalJSON(ctx context.Context) ([]byte, error) {
if ctx != nil {
s := ctx.Value(jsonMarshalOptionsCtxKey{})
//nolint:forcetypeassert // We know the type of the value.
if s != nil && s.(*JSONMarshalOptions).RawDataAsString {
// We should serialize RawData as a string.
//nolint:wrapcheck // If we didn't implement MarshalJSON this would be done by the json package.
return json.Marshal(string(d))
}
}
Expand Down
7 changes: 6 additions & 1 deletion opencdc/serializer.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package opencdc

import (
"context"
"fmt"

"github.com/goccy/go-json"
)
Expand All @@ -38,5 +39,9 @@ func (s JSONSerializer) Serialize(r Record) ([]byte, error) {
// instead of pointer.
s = JSONSerializer{}
}()
return json.MarshalContext(ctx, r)
bytes, err := json.MarshalContext(ctx, r)
if err != nil {
return nil, fmt.Errorf("failed to serialize record to JSON: %w", err)
}
return bytes, nil
}
3 changes: 1 addition & 2 deletions opencdc/serializer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ import (
)

func TestJSONSerializer(t *testing.T) {
t.Skip()
is := is.New(t)
rec := Record{
Position: Position("standing"),
Operation: OperationUpdate,
Expand Down Expand Up @@ -62,6 +60,7 @@ func TestJSONSerializer(t *testing.T) {

for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
is := is.New(t)
rec.SetSerializer(tc.serializer)
b := rec.Bytes()
is.Equal(cmp.Diff(string(b), tc.want), "")
Expand Down

0 comments on commit 49ce3f3

Please sign in to comment.