diff --git a/ui/amqp_test.go b/ui/amqp_test.go index 4216079..a75c571 100644 --- a/ui/amqp_test.go +++ b/ui/amqp_test.go @@ -33,6 +33,18 @@ func TestNewAmqp(t *testing.T) { client.Consume(event) + event = &yabl.Event{ + Tag: &tag, + Field: &field, + ActionName: &action, + Object: nil, + //unit: 3, + Updated: &now, + Value: nil, + } + + client.Consume(event) + client.Stop() }) diff --git a/yabl/strings.go b/yabl/strings.go index 75b5457..a25f47f 100644 --- a/yabl/strings.go +++ b/yabl/strings.go @@ -217,19 +217,24 @@ func (c ConnectedOut8bitType) String() string { } func (u *Event) MarshalJSON() ([]byte, error) { + var val *string + if u.Value != nil { + s := fmt.Sprintf("%v", u.Value) + val = &s + } return json.Marshal(struct { Host *string Unit uint ActionName *AName Field *FName Updated *time.Time - Value string + Value *string `json:"Value,omitempty"` }{ Host: u.Tag, Unit: u.GetUnitId(), ActionName: u.ActionName, Field: u.Field, Updated: u.Updated, - Value: fmt.Sprintf("%v", u.Value), + Value: val, }) }