-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Serialization Error When Loading Multi-Document YAML in fabric8 Kubernetes Client #6009
Comments
@fengyinqiao : Hello, we have a test for verifying this multi-line document YAML deserialization. Could you please check if your YAML is similar to this? kubernetes-client/kubernetes-client/src/test/resources/test-list.yml Lines 17 to 20 in e97a19e
This yaml gets used in KubernetesClientImplTest |
@rohanKanojia Really thank's for your reply! my YAML is as below:
|
@fengyinqiao : When I copy paste your YAML and add this test, it seems to pass. @Test
void multiline() {
// Given
// When
try (KubernetesClient kubernetesClient = new KubernetesClientBuilder().build()) {
List<HasMetadata> result = kubernetesClient.load(KubernetesClientImplTest.class.getResourceAsStream("/multi-line.yml")).items();
// Then
assertThat(result)
.hasSize(2)
.hasAtLeastOneElementOfType(GenericKubernetesResource.class)
.hasAtLeastOneElementOfType(GenericKubernetesResource.class);
}
} |
@rohanKanojia Thanks for your code. It does work. And I find another way based on my code just now, it also works:
so, why my original code is wrong? |
Are you using |
@rohanKanojia I get null , use below code:
|
@fengyinqiao : Sorry for late reply, I tried your sample but I'm getting a different error:
Serialization.unmarshal is returning a if I change code like this it start working : try (InputStream is = new ByteArrayInputStream(ymlContent.getBytes(StandardCharsets.UTF_8))) {
List<HasMetadata> kubernetesResourceList = Serialization.unmarshal(is);
assertNull(kubernetesResourceList)
} |
@rohanKanojia Thanks for your time and reply, I tried the code snippet below later, and it works.
|
Describe the bug
Encountering a deserialization error when attempting to use the Serialization.unmarshal method to handle a YAML string containing multiple Kubernetes resource definitions separated by ---, and trying to deserialize it as List.class.
Error Details:
Fabric8 Kubernetes Client version
6.9.2
Steps to reproduce
Actual Behavior:
Throws a type mismatch exception when the YAML definitions contain only a single resource object instead of an array.
Expected behavior
The method should correctly parse the multi-document YAML string and deserialize each definition into a corresponding list of Kubernetes resource objects.
Runtime
Kubernetes (vanilla)
Kubernetes API Server version
1.23
Environment
macOS
Fabric8 Kubernetes Client Logs
No response
Additional context
Consider enhancing the Serialization.unmarshal method to more intelligently handle both single objects and arrays of objects, or clarify in the documentation how such cases should be handled.
The text was updated successfully, but these errors were encountered: