Skip to content

[Bug] api-go failing to properly handle nested empty objects for shorthand payloads #349

@cretz

Description

@cretz

Describe the bug

If the payload is something like {"greeting":{}}, it marshals to {"greeting":}. If you take api-go as of this time and apply the following test patch you can see the error:

--- a/internal/temporalcommonv1/payload_json_test.go
+++ b/internal/temporalcommonv1/payload_json_test.go
@@ -82,6 +82,16 @@ var tests = []struct {
 			},
 		},
 	},
+}, {
+	name:          "json/plain with empty object",
+	longformJSON:  `{"metadata":{"encoding":"anNvbi9wcm90b2J1Zg=="},"data":"eyJncmVldGluZyI6IHt9fQ=="}`,
+	shorthandJSON: `{"greeting": {}}`,
+	pb: &common.Payload{
+		Metadata: map[string][]byte{
+			"encoding": []byte("json/plain"),
+		},
+		Data: []byte(`{"greeting":{}}`),
+	},
 }}
 
 func TestMaybeMarshal_ShorthandEnabled(t *testing.T) {

(sorry for opening in api repo, the api-go repo has issues disabled for good reason)

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions