Skip to content
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

Closed
saskiawagenaar opened this issue Aug 14, 2018 · 11 comments
Closed

YAML.dump ignores Boolean values #340

saskiawagenaar opened this issue Aug 14, 2018 · 11 comments
Labels
lifecycle/frozen Indicates that an issue or PR should not be auto-closed due to staleness.

Comments

@saskiawagenaar
Copy link
Contributor

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
Copy link
Contributor

@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
Test failes because a key with Boolean value is ignored.
See kubernetes-client#340.
@davidxia
Copy link
Contributor

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
Test fails because a key with Boolean value is ignored.
See kubernetes-client#340.
@mihirnimbalkar
Copy link

I think I'm hitting the same problem at V1SecurityContext#privileged field in #531

@fejta-bot
Copy link

Issues go stale after 90d of inactivity.
Mark the issue as fresh with /remove-lifecycle stale.
Stale issues rot after an additional 30d of inactivity and eventually close.

If this issue is safe to close now please do so with /close.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
/lifecycle stale

@k8s-ci-robot k8s-ci-robot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Jun 17, 2019
@davidxia
Copy link
Contributor

/remove-lifecycle stale

@k8s-ci-robot k8s-ci-robot removed the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Jun 17, 2019
@ghost
Copy link

ghost commented Sep 10, 2019

A temporary workaround as following (may not work for some scenario)

//Since Gson serialization is not affected, so we can convert to JSON
Gson gson = new Gson();
String json = gson.toJson(crd);

//you can uses the JSON output in kubectl, so optionally, use the snakeYAML's function to convert JSON to YAML
org.yaml.snakeyaml.Yaml yaml = new org.yaml.snakeyaml.Yaml();
Object result = yaml.load(json);
String output = yaml.dumpAsMap(result);

@fejta-bot
Copy link

Issues go stale after 90d of inactivity.
Mark the issue as fresh with /remove-lifecycle stale.
Stale issues rot after an additional 30d of inactivity and eventually close.

If this issue is safe to close now please do so with /close.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
/lifecycle stale

@k8s-ci-robot k8s-ci-robot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Dec 9, 2019
@davidxia
Copy link
Contributor

davidxia commented Dec 9, 2019

/remove-lifecycle stale

@k8s-ci-robot k8s-ci-robot removed the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Dec 9, 2019
@fejta-bot
Copy link

Issues go stale after 90d of inactivity.
Mark the issue as fresh with /remove-lifecycle stale.
Stale issues rot after an additional 30d of inactivity and eventually close.

If this issue is safe to close now please do so with /close.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
/lifecycle stale

@k8s-ci-robot k8s-ci-robot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Mar 8, 2020
@brendandburns
Copy link
Contributor

/lifecycle frozen

@k8s-ci-robot k8s-ci-robot added lifecycle/frozen Indicates that an issue or PR should not be auto-closed due to staleness. and removed lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. labels Mar 8, 2020
@brendandburns
Copy link
Contributor

I'm going to close this as I believe that we have advanced the code generator past the commit with the fix for this issue (and this issue is pretty old). We can reopen if it reoccurs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lifecycle/frozen Indicates that an issue or PR should not be auto-closed due to staleness.
Projects
None yet
Development

No branches or pull requests

6 participants