-
Notifications
You must be signed in to change notification settings - Fork 2k
Description
Problem:
When performing a YAML.dump on a model object the value of Boolean fields are missing in the output.
For example, when running a YAML.dump on a V1Deployment which has a V1Container where stdin equals true, the value of stdin will not be present in the YAML.dump of the V1Deployment.
Reproduction path:
Load the following yaml into a V1Deployment via Yaml.loadAs:
---
apiVersion: apps/v1
kind: Deployment
spec:
template:
spec:
containers:
- image: example
name: example
stdin: true
Then run a Yaml.dump on the V1Deployment, the result equals:
---
apiVersion: apps/v1
kind: Deployment
spec:
template:
spec:
containers:
- image: example
name: example
The value of stdin is missing in the dumped yaml, although it is read in correctly in the V1Deployment object.
Probable cause:
In version 2.3.0 of the Swagger codegeneration a bug was introduced in generating non-primitive Boolean getters. They now follow the naming conventions for primitive booleans, which equal is<booleanName> instead of get<booleanName>. However, this naming convention does not hold for Boolean primitives, their getters should be named get<BooleanName>.
(See also http://www.oracle.com/technetwork/articles/javaee/spec-136004.html, paragraph 8.3)
Snakeyaml uses getter methods to determine which fields are readable. It cannot find a correct getter for all Boolean fields, and therefore it will not serialize this field.
This issue is introduced in the Swagger codegeneration via swagger-api/swagger-codegen#4882 and fixed via OpenAPITools/openapi-generator#432.
Note 1:
Yaml.loadAs has no issues, because the setters of Boolean fields are named correctly and therefore it can deserialze Yaml to Java beans.
Note 2:
Luckily the Boolean fields seem to be passed correctly to kubernetes, because here Gson is used for serialization, which does not use getters and setters to serialize Java beans.