Skip to content

Commit 9ef877b

Browse files
Fix Watch.Response deserialization to use JSON instance's GSON
Co-authored-by: brendandburns <[email protected]>
1 parent ea892a2 commit 9ef877b

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

util/src/main/java/io/kubernetes/client/util/Watch.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,10 +169,10 @@ protected boolean isStatus(String line) throws IOException {
169169

170170
protected Response<T> parseLine(String line) throws IOException {
171171
if (!isStatus(line)) {
172-
return json.deserialize(line, watchType);
172+
return json.getGson().fromJson(line, watchType);
173173
}
174174
Type statusType = new TypeToken<Response<V1Status>>() {}.getType();
175-
Response<V1Status> status = json.deserialize(line, statusType);
175+
Response<V1Status> status = json.getGson().fromJson(line, statusType);
176176
return new Response<T>(status.type, status.object);
177177
}
178178

util/src/test/java/io/kubernetes/client/util/WatchDynamicObjectTest.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ class WatchDynamicObjectTest {
2626
@Test
2727
void watchAddedEventShouldPreserveRawData() throws IOException {
2828
JSON json = new JSON();
29+
// Register the DynamicKubernetesTypeAdaptorFactory to properly handle DynamicKubernetesObject
30+
json.setGson(json.getGson().newBuilder()
31+
.registerTypeAdapterFactory(new io.kubernetes.client.util.generic.dynamic.DynamicKubernetesTypeAdaptorFactory())
32+
.create());
2933
Watch<DynamicKubernetesObject> watch =
3034
new Watch<>(
3135
json, null, new TypeToken<Watch.Response<DynamicKubernetesObject>>() {}.getType(), null);
@@ -54,6 +58,10 @@ void watchAddedEventShouldPreserveRawData() throws IOException {
5458
@Test
5559
void watchModifiedEventShouldPreserveRawData() throws IOException {
5660
JSON json = new JSON();
61+
// Register the DynamicKubernetesTypeAdaptorFactory to properly handle DynamicKubernetesObject
62+
json.setGson(json.getGson().newBuilder()
63+
.registerTypeAdapterFactory(new io.kubernetes.client.util.generic.dynamic.DynamicKubernetesTypeAdaptorFactory())
64+
.create());
5765
Watch<DynamicKubernetesObject> watch =
5866
new Watch<>(
5967
json, null, new TypeToken<Watch.Response<DynamicKubernetesObject>>() {}.getType(), null);

0 commit comments

Comments
 (0)