Skip to content

Commit

Permalink
json output error on unknown tags, fixes #57
Browse files Browse the repository at this point in the history
  • Loading branch information
spali committed Apr 17, 2024
1 parent 1cf03c5 commit 52222f7
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
5 changes: 5 additions & 0 deletions cmd/e3dc/json_output_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion rscp/tag_functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 52222f7

Please sign in to comment.