Fix Watch.Response deserialization to preserve DynamicKubernetesObject raw data
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 calljson.getGson().fromJson()directly instead ofjson.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 inobjecthas only metadata.rawis empty (null). (The object's raw data is provided fortype"MODIFIED")Client Version
v19Java 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.
[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.
Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment
[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.
Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment