Skip to content

Commit a55f17a

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

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

routing/http/types/record_bitswap.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ type BitswapRecord struct {
2828
Schema string
2929
Protocol string
3030
ID *peer.ID
31-
Addrs []Multiaddr
31+
Addrs []Multiaddr `json:",omitempty"`
3232
}
3333

3434
func (br *BitswapRecord) GetSchema() string {

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)