diff --git a/v5/marshaling.go b/v5/marshaling.go new file mode 100644 index 0000000..6cc65cf --- /dev/null +++ b/v5/marshaling.go @@ -0,0 +1,7 @@ +package v5 + +import "encoding/json" + +func (t Tag) MarshalJSON() ([]byte, error) { + return json.Marshal(t.Name) +} diff --git a/v5/marshaling_test.go b/v5/marshaling_test.go new file mode 100644 index 0000000..199b22a --- /dev/null +++ b/v5/marshaling_test.go @@ -0,0 +1,24 @@ +package v5 + +import ( + "encoding/json" + "reflect" + "testing" +) + +func TestTag_MarshalJSON(t *testing.T) { + tags := []Tag{ + {"first", "#3e89b6", false}, + {"second", "#ffa654", false}, + } + names := []byte(`["first","second"]`) + str, err := json.Marshal(tags) + + if err != nil { + t.Errorf("%v", err.Error()) + } + + if !reflect.DeepEqual(str, names) { + t.Errorf("Marshaled: %#v\nExpected: %#v\n", str, names) + } +}