From 782079d699a57bfbc60b98c1678fdbb7661b2453 Mon Sep 17 00:00:00 2001 From: Brendan Burns Date: Wed, 10 Jan 2018 22:37:49 -0800 Subject: [PATCH] When watch can't parse an object, try to parse it to a Status. --- .../java/io/kubernetes/client/util/Watch.java | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/util/src/main/java/io/kubernetes/client/util/Watch.java b/util/src/main/java/io/kubernetes/client/util/Watch.java index 6ae158f41f..d72de1247d 100644 --- a/util/src/main/java/io/kubernetes/client/util/Watch.java +++ b/util/src/main/java/io/kubernetes/client/util/Watch.java @@ -12,13 +12,16 @@ */ package io.kubernetes.client.util; +import com.google.gson.JsonParseException; import com.google.gson.annotations.SerializedName; +import com.google.gson.reflect.TypeToken; import com.squareup.okhttp.Call; import com.squareup.okhttp.ResponseBody; import io.kubernetes.client.ApiClient; import io.kubernetes.client.ApiException; import io.kubernetes.client.JSON; +import io.kubernetes.client.models.V1Status; import java.io.IOException; import java.lang.reflect.Type; import java.util.Iterator; @@ -46,9 +49,18 @@ public static class Response { @SerializedName("object") public T object; + public V1Status status; + Response(String type, T object) { this.type = type; this.object = object; + this.status = null; + } + + Response(String type, V1Status status) { + this.type = type; + this.object = null; + this.status = status; } } @@ -99,7 +111,13 @@ public Response next() { if (line == null) { throw new RuntimeException("Null response from the server."); } - return json.deserialize(line, watchType); + try { + return json.deserialize(line, watchType); + } catch (JsonParseException ex) { + Type statusType = new TypeToken>(){}.getType(); + Response status = json.deserialize(line, statusType); + return new Response(status.type, status.object); + } } catch (IOException e) { throw new RuntimeException("IO Exception during next method.", e); }