java icon indicating copy to clipboard operation
java copied to clipboard

Fix Watch.Response deserialization to preserve DynamicKubernetesObject raw data

Open Copilot opened this issue 3 months ago • 2 comments

Watch.Response objects were not preserving the raw JSON data for DynamicKubernetesObject instances. The issue affected all event types (ADDED, MODIFIED, DELETED), despite the original report focusing on ADDED.

Root Cause

Watch.parseLine() called json.deserialize(), which uses the global static GSON instance. DynamicKubernetesApi registers DynamicKubernetesTypeAdaptorFactory on its ApiClient's GSON instance, but Watch wasn't using it.

Changes

  • Watch.java: Changed parseLine() to call json.getGson().fromJson() directly instead of json.deserialize(), ensuring it uses the ApiClient-configured GSON instance with registered TypeAdapters
  • WatchDynamicObjectTest.java: Added tests verifying raw data preservation for DynamicKubernetesObject

Example

// After fix, raw JSON is properly preserved
DynamicKubernetesApi api = new DynamicKubernetesApi(...);
Watchable<DynamicKubernetesObject> watch = api.watch(namespace);

for (Watch.Response<DynamicKubernetesObject> event : watch) {
  // event.object.getRaw() now contains full JSON including spec, status, etc.
  JsonObject raw = event.object.getRaw();
  System.out.println(raw.get("spec"));  // Works for all event types
}
Original prompt

This section details on the original issue you should resolve

<issue_title>Watch.Response with type ADDED does not provide object's data</issue_title> <issue_description>Describe the bug

If the response received from calling GenericKubernetesApi.watch has type "ADDED", the KubernetesObject in object has only metadata. raw is empty (null). (The object's raw data is provided for type "MODIFIED")

Client Version v19

Java Version Java 17

To Reproduce Call the method, add a Kubernetes object, look at the result.

Expected behavior The (raw) data should be provided. </issue_description>

Comments on the Issue (you are @copilot in this section)

  • Fixes kubernetes-client/java#3215

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot avatar Nov 17 '25 22:11 Copilot

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: Copilot Once this PR has been reviewed and has the lgtm label, please ask for approval from brendandburns. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment Approvers can cancel approval by writing /approve cancel in a comment

k8s-ci-robot avatar Nov 17 '25 22:11 k8s-ci-robot

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: Copilot Once this PR has been reviewed and has the lgtm label, please ask for approval from brendandburns. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment Approvers can cancel approval by writing /approve cancel in a comment

k8s-ci-robot avatar Nov 17 '25 22:11 k8s-ci-robot