@@ -75,7 +75,11 @@ public void bind(ExposedPort exposedPort, Binding binding) {
7575 Binding [] bindings = ports .get (exposedPort );
7676 ports .put (exposedPort , (Binding []) ArrayUtils .add (bindings , binding ));
7777 } else {
78- ports .put (exposedPort , new Binding []{binding });
78+ if (binding == null ) {
79+ ports .put (exposedPort , null );
80+ } else {
81+ ports .put (exposedPort , new Binding []{binding });
82+ }
7983 }
8084 }
8185
@@ -282,12 +286,16 @@ public Ports deserialize(JsonParser jsonParser, DeserializationContext deseriali
282286
283287 Map .Entry <String , JsonNode > portNode = it .next ();
284288 JsonNode bindingsArray = portNode .getValue ();
285- for (int i = 0 ; i < bindingsArray .size (); i ++) {
286- JsonNode bindingNode = bindingsArray .get (i );
287- if (!bindingNode .equals (NullNode .getInstance ())) {
288- String hostIp = bindingNode .get ("HostIp" ).textValue ();
289- int hostPort = bindingNode .get ("HostPort" ).asInt ();
290- out .bind (ExposedPort .parse (portNode .getKey ()), new Binding (hostIp , hostPort ));
289+ if (bindingsArray .equals (NullNode .getInstance ())) {
290+ out .bind (ExposedPort .parse (portNode .getKey ()), null );
291+ } else {
292+ for (int i = 0 ; i < bindingsArray .size (); i ++) {
293+ JsonNode bindingNode = bindingsArray .get (i );
294+ if (!bindingNode .equals (NullNode .getInstance ())) {
295+ String hostIp = bindingNode .get ("HostIp" ).textValue ();
296+ int hostPort = bindingNode .get ("HostPort" ).asInt ();
297+ out .bind (ExposedPort .parse (portNode .getKey ()), new Binding (hostIp , hostPort ));
298+ }
291299 }
292300 }
293301 }
@@ -304,14 +312,18 @@ public void serialize(Ports portBindings, JsonGenerator jsonGen,
304312 jsonGen .writeStartObject ();
305313 for (Entry <ExposedPort , Binding []> entry : portBindings .getBindings ().entrySet ()){
306314 jsonGen .writeFieldName (entry .getKey ().toString ());
307- jsonGen .writeStartArray ();
308- for (Binding binding : entry .getValue ()) {
309- jsonGen .writeStartObject ();
310- jsonGen .writeStringField ("HostIp" , binding .getHostIp () == null ? "" : binding .getHostIp ());
311- jsonGen .writeStringField ("HostPort" , binding .getHostPort () == null ? "" : binding .getHostPort ().toString ());
312- jsonGen .writeEndObject ();
315+ if (entry .getValue () != null ) {
316+ jsonGen .writeStartArray ();
317+ for (Binding binding : entry .getValue ()) {
318+ jsonGen .writeStartObject ();
319+ jsonGen .writeStringField ("HostIp" , binding .getHostIp () == null ? "" : binding .getHostIp ());
320+ jsonGen .writeStringField ("HostPort" , binding .getHostPort () == null ? "" : binding .getHostPort ().toString ());
321+ jsonGen .writeEndObject ();
322+ }
323+ jsonGen .writeEndArray ();
324+ } else {
325+ jsonGen .writeNull ();
313326 }
314- jsonGen .writeEndArray ();
315327 }
316328 jsonGen .writeEndObject ();
317329 }
0 commit comments