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

Open
saskiawagenaar opened this issue Aug 14, 2018 · 10 comments
Open

YAML.dump ignores Boolean values #340

saskiawagenaar opened this issue Aug 14, 2018 · 10 comments

Comments

@saskiawagenaar
Copy link
Contributor

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

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

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

@mihirnimbalkar mihirnimbalkar commented Mar 19, 2019

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

@fejta-bot
Copy link

@fejta-bot fejta-bot commented Jun 17, 2019

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

@davidxia
Copy link
Contributor

@davidxia davidxia commented Jun 17, 2019

/remove-lifecycle stale

@hinyinlam-pivotal
Copy link

@hinyinlam-pivotal hinyinlam-pivotal 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

@fejta-bot fejta-bot commented Dec 9, 2019

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

@davidxia
Copy link
Contributor

@davidxia davidxia commented Dec 9, 2019

/remove-lifecycle stale

@fejta-bot
Copy link

@fejta-bot fejta-bot commented Mar 8, 2020

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

@brendandburns
Copy link
Contributor

@brendandburns brendandburns commented Mar 8, 2020

/lifecycle frozen

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
7 participants