Skip to content

Commit a24e870

Browse files
committed
fix: do not produce null fields in marshalled json
1 parent bdd7f87 commit a24e870

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

routing/http/types/record_peer.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,18 @@ func (pr PeerRecord) MarshalJSON() ([]byte, error) {
6464
m[key] = val
6565
}
6666
}
67+
68+
// Schema and ID must always be set.
6769
m["Schema"] = pr.Schema
6870
m["ID"] = pr.ID
69-
m["Addrs"] = pr.Addrs
70-
m["Protocols"] = pr.Protocols
71+
72+
if pr.Addrs != nil {
73+
m["Addrs"] = pr.Addrs
74+
}
75+
76+
if pr.Protocols != nil {
77+
m["Protocols"] = pr.Protocols
78+
}
79+
7180
return drjson.MarshalJSONBytes(m)
7281
}

0 commit comments

Comments
 (0)