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

YAML.dump ignores Boolean values #340

Open
saskiawagenaar opened this Issue Aug 14, 2018 · 2 comments

Comments

Projects
None yet
3 participants
@saskiawagenaar
Contributor

saskiawagenaar commented Aug 14, 2018

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.

@brendandburns

This comment has been minimized.

Collaborator

brendandburns commented Aug 19, 2018

@mbohlool fyi, looks like we should update the version of the generator that we use...

davidxia added a commit to davidxia/java that referenced this issue Nov 10, 2018

Add test for Yaml.dump() on Boolean values
Test failes because a key with Boolean value is ignored.
See kubernetes-client#340.
@davidxia

This comment has been minimized.

Contributor

davidxia commented Nov 10, 2018

I just ran into this. I created a test that fails here. I tried to fix but don't know how.

Does this commit hash need to be updated to a commit in OpenAPITools/openapi-generator now?

davidxia added a commit to davidxia/java that referenced this issue Nov 11, 2018

Add test for Yaml.dump() on Boolean values
Test fails because a key with Boolean value is ignored.
See kubernetes-client#340.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment