Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use raw JSON to convert payload to string #366

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions converter/data_converter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,10 @@ func TestToStrings(t *testing.T) {

want := []string{
"dGVzdA",
"[hello world]",
"hello world",
`["hello","world"]`,
`"hello world"`,
"42",
"{A:hi B:3}",
`{"A":"hi","B":3}`,
}

require.Equal(t, want, got)
Expand Down
14 changes: 1 addition & 13 deletions converter/json_payload_converter.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ package converter
import (
"encoding/json"
"fmt"
"strings"

commonpb "go.temporal.io/api/common/v1"
)
Expand Down Expand Up @@ -61,18 +60,7 @@ func (c *JSONPayloadConverter) FromPayload(payload *commonpb.Payload, valuePtr i

// ToString converts payload object into human readable string.
func (c *JSONPayloadConverter) ToString(payload *commonpb.Payload) string {
var value interface{}
err := c.FromPayload(payload, &value)
if err != nil {
return err.Error()
}
s := fmt.Sprintf("%+v", value)
if strings.HasPrefix(s, "map[") {
s = strings.TrimPrefix(s, "map[")
s = strings.TrimSuffix(s, "]")
s = fmt.Sprintf("{%s}", s)
}
return s
return string(payload.GetData())
}

// Encoding returns MetadataEncodingJSON.
Expand Down
2 changes: 1 addition & 1 deletion converter/payload_converter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ func TestJsonPayloadConverter(t *testing.T) {
assert.Equal(t, "qwe", wt4.Name)

s := pc.ToString(payload)
assert.Equal(t, "{Age:0 Name:qwe}", s)
assert.Equal(t, `{"Name":"qwe","Age":0}`, s)
}

func TestProtoJsonPayloadConverter_Nil(t *testing.T) {
Expand Down
1 change: 0 additions & 1 deletion converter/proto_json_payload_converter.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,6 @@ func (c *ProtoJSONPayloadConverter) FromPayload(payload *commonpb.Payload, value

// ToString converts payload object into human readable string.
func (c *ProtoJSONPayloadConverter) ToString(payload *commonpb.Payload) string {
// We can't do anything better here.
return string(payload.GetData())
}

Expand Down