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

Allow omitting empty collections via DefaultValuesHandling #608

Merged
merged 9 commits into from Jun 12, 2021

Conversation

premun
Copy link
Contributor

@premun premun commented May 4, 2021

Motivation
Sometimes, you cannot cannot afford to null your enumerables but you don't want them in your YAML.
This default value handling policy allows to prevent serialization of empty arrays/lists/dictionaries into

value: []

Change
Added 2 new options:

  • DefaultValuesHandling.OmitDefaultsOrEmpty
  • DefaultValuesHandling.OmitNullOrEmpty
    which turns on omitting of empty collections.

@premun premun changed the title Add DefaultValuesHandling.OmitDefaultsOrEmpty Allow omitting empty collections via DefaultValuesHandling May 4, 2021
@premun
Copy link
Contributor Author

premun commented May 9, 2021

@aaubry would it be possible to get this looked at? It would help my other project a lot to have this capability

premun added a commit to sharpliner/sharpliner that referenced this pull request May 17, 2021
This is a temporary workaround before aaubry/YamlDotNet#608 gets merged.

This makes the YAML not contain bunch of rows like this:
```
variables: []
```
premun added a commit to sharpliner/sharpliner that referenced this pull request May 17, 2021
**Makes the project use the pipeline defined using Sharpliner inside the `Sharpliner.CI` project!**

Adds an AzDO task that will verify whether you have published and commited all changes into YAML files. (resolves #3)

The many empty arrays in the YAML will be gone once we check in aaubry/YamlDotNet#608
@aaubry
Copy link
Owner

aaubry commented May 30, 2021

@aaubry would it be possible to get this looked at? It would help my other project a lot to have this capability

I'm sorry, I wasn't able to look at this until today. I'm reviewing the PR now.

Copy link
Owner

@aaubry aaubry left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this feature is interesting, but requires some small design changes so that we don't get stuck in the future.

@aaubry
Copy link
Owner

aaubry commented Jun 12, 2021

Thanks and sorry about the slow response time.

@aaubry aaubry merged commit 78a57da into aaubry:master Jun 12, 2021
@aaubry
Copy link
Owner

aaubry commented Jun 13, 2021

This feature has been released in version 11.2.0.

@premun premun deleted the DefaultValuesOrEmpty branch June 14, 2021 07:37
@premun
Copy link
Contributor Author

premun commented Jun 14, 2021

Thanks @aaubry!!

@premun
Copy link
Contributor Author

premun commented Jun 1, 2022

@tjstjsgt we have made these options into [Flags] as per this comment: #608 (comment)

So you could set the policy to DefaultValuesHandling.OmitNull | DefaultValuesHandling.OmitEmpty which should do the trick.

Or is there a problem?

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

Successfully merging this pull request may close these issues.

None yet

2 participants