From 52222f7adbd7c6b60f5d9af6ec1f31bcc5f3f55a Mon Sep 17 00:00:00 2001 From: Thomas Spalinger Date: Wed, 17 Apr 2024 22:16:36 +0200 Subject: [PATCH] json output error on unknown tags, fixes #57 --- cmd/e3dc/json_output_test.go | 5 +++++ rscp/tag_functions.go | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/cmd/e3dc/json_output_test.go b/cmd/e3dc/json_output_test.go index e808c60..6851e8d 100644 --- a/cmd/e3dc/json_output_test.go +++ b/cmd/e3dc/json_output_test.go @@ -154,6 +154,11 @@ func TestJSONSimpleMessage_MarshalJSON(t *testing.T) { []byte(`{"EMS_MANUAL_CHARGE_LASTSTART":"1970-01-01T00:00:00Z"}`), false, }, + {"Unknown Tag to String key", + JSONMessage{25166461: 0}, + []byte(`{"25166461":0}`), + false, + }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { diff --git a/rscp/tag_functions.go b/rscp/tag_functions.go index d70118f..2538140 100644 --- a/rscp/tag_functions.go +++ b/rscp/tag_functions.go @@ -23,7 +23,7 @@ func (t Tag) MarshalJSON() ([]byte, error) { if t.IsATag() { return json.Marshal(t.String()) } - return []byte(fmt.Sprintf("%d", t)), nil + return []byte(fmt.Sprintf("\"%d\"", t)), nil } // UnmarshalJSON implements the json.Unmarshaler interface for Tag