@@ -232,9 +232,12 @@ func (ep *hnsEndpoint) MarshalJSON() ([]byte, error) {
232232 epMap ["Type" ] = ep .Type
233233 epMap ["profileID" ] = ep .profileID
234234 epMap ["MacAddress" ] = ep .macAddress .String ()
235- epMap ["Addr" ] = ep .addr .String ()
236- epMap ["gateway" ] = ep .gateway .String ()
237-
235+ if ep .addr .IP != nil {
236+ epMap ["Addr" ] = ep .addr .String ()
237+ }
238+ if ep .gateway != nil {
239+ epMap ["gateway" ] = ep .gateway .String ()
240+ }
238241 epMap ["epOption" ] = ep .epOption
239242 epMap ["epConnectivity" ] = ep .epConnectivity
240243 epMap ["PortMapping" ] = ep .portMapping
@@ -251,7 +254,6 @@ func (ep *hnsEndpoint) UnmarshalJSON(b []byte) error {
251254 if err = json .Unmarshal (b , & epMap ); err != nil {
252255 return fmt .Errorf ("Failed to unmarshal to endpoint: %v" , err )
253256 }
254-
255257 if v , ok := epMap ["MacAddress" ]; ok {
256258 if ep .macAddress , err = net .ParseMAC (v .(string )); err != nil {
257259 return types .InternalErrorf ("failed to decode endpoint MAC address (%s) after json unmarshal: %v" , v .(string ), err )
@@ -262,7 +264,9 @@ func (ep *hnsEndpoint) UnmarshalJSON(b []byte) error {
262264 return types .InternalErrorf ("failed to decode endpoint IPv4 address (%s) after json unmarshal: %v" , v .(string ), err )
263265 }
264266 }
265-
267+ if v , ok := epMap ["gateway" ]; ok {
268+ ep .gateway = net .ParseIP (v .(string ))
269+ }
266270 ep .id = epMap ["id" ].(string )
267271 ep .Type = epMap ["Type" ].(string )
268272 ep .nid = epMap ["nid" ].(string )
0 commit comments