Custom JSON marshalling for PackageDiff, updated test for snapshot diff API. #168

This commit is contained in:
Andrey Smirnov
2015-02-05 01:34:02 +03:00
parent 25d048fe49
commit 398303235a
2 changed files with 39 additions and 4 deletions
+23
View File
@@ -2,6 +2,8 @@ package deb
import (
"bytes"
"encoding/json"
"github.com/AlekSi/pointer"
"github.com/ugorji/go/codec"
"sort"
)
@@ -154,6 +156,27 @@ type PackageDiff struct {
Left, Right *Package
}
// Check interface
var (
_ json.Marshaler = PackageDiff{}
)
// MarshalJSON implements json.Marshaler interface
func (d PackageDiff) MarshalJSON() ([]byte, error) {
serialized := struct {
Left, Right *string
}{}
if d.Left != nil {
serialized.Left = pointer.ToString(string(d.Left.Key("")))
}
if d.Right != nil {
serialized.Right = pointer.ToString(string(d.Right.Key("")))
}
return json.Marshal(serialized)
}
// PackageDiffs is a list of PackageDiff records
type PackageDiffs []PackageDiff