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
Export Float and Double as String #1561
Export Float and Double as String #1561
Conversation
Line 99 in f9d526b
I'm not sure if |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
seems like that will work.
Confirmed, values in this format are not importable. Interestingly you can run the following snippet through http://yamllint.com and the result is "valid YAML" with
I wonder if |
Looks good! |
...ness/src/test/java/io/jenkins/plugins/casc/impl/configurators/DataBoundConfiguratorTest.java
Show resolved
Hide resolved
Codecov Report
@@ Coverage Diff @@
## master #1561 +/- ##
============================================
+ Coverage 81.01% 81.04% +0.03%
Complexity 810 810
============================================
Files 66 66
Lines 2370 2369 -1
Branches 328 328
============================================
Hits 1920 1920
Misses 349 349
+ Partials 101 100 -1
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Before we merge from what I remember this did work standalone with snake yaml and we couldn’t figure out why it didn’t work in jcasc, or is it a snake yaml limitation? we can ship this workaround but would be interested to know more of why this is needed |
foo.setDbl(12.34); | ||
foo.setFlt(1f); // whole numbers are exported as "<number>.0" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also true for double
s
Hi @timja , I understand how this PR masks a potential bug in snakeyaml, but I didn't find any evidence of said bug and hit a dead end while debugging, as described in #1560. We've heard multiple reports that exported CasC YAML isn't imported properly, and I don't think it's immediately obvious to people that decimal numbers must be quoted for the import to work. So this PR takes care of it automatically, sticking to the rule that what is exported is also importable. |
Possible solution for #1560.
Setting
raw
tofalse
forFloat
andDouble
types tellsConfigurationAsCode#toYaml
to export using theDOUBLE_QUOTED
style instead of the currentPLAIN
style:configuration-as-code-plugin/plugin/src/main/java/io/jenkins/plugins/casc/ConfigurationAsCode.java
Lines 548 to 552 in f9d526b