From 701e258acf7d12e69a838404d364f41886b9c482 Mon Sep 17 00:00:00 2001 From: Calum Murray Date: Fri, 29 Mar 2024 05:55:40 -0400 Subject: [PATCH] fix: func invoke unmarshals json before setting it in the event (#2256) Signed-off-by: Calum Murray --- pkg/functions/invoke.go | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/pkg/functions/invoke.go b/pkg/functions/invoke.go index 11cf58f7ac..0294930302 100644 --- a/pkg/functions/invoke.go +++ b/pkg/functions/invoke.go @@ -3,6 +3,7 @@ package functions import ( "bytes" "context" + "encoding/json" "errors" "fmt" "io" @@ -152,7 +153,17 @@ func sendEvent(ctx context.Context, route string, m InvokeMessage, t http.RoundT event.SetID(m.ID) event.SetSource(m.Source) event.SetType(m.Type) - if err = event.SetData(m.ContentType, m.Data); err != nil { + if m.ContentType == "application/json" { + var d interface{} + err = json.Unmarshal([]byte(m.Data), &d) + if err != nil { + return + } + err = event.SetData(m.ContentType, d) + if err != nil { + return + } + } else if err = event.SetData(m.ContentType, m.Data); err != nil { return }