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

Add new line to be specified for JSON formatting #100890

Conversation

martincostello
Copy link
Member

Allow the new line string to use for indented JSON to be specified through options.

Resolves #84117.

Allow the new line string to use for indented JSON to be specified through options.
Resolves dotnet#84117.
Copy link

Note regarding the new-api-needs-documentation label:

This serves as a reminder for when your PR is modifying a ref *.cs file and adding/modifying public APIs, please make sure the API implementation in the src *.cs file is documented with triple slash comments, so the PR reviewers can sign off that change.

@dotnet-policy-service dotnet-policy-service bot added the community-contribution Indicates that the PR has been added by a community member label Apr 10, 2024
@martincostello
Copy link
Member Author

@eiriktsarpalis I've left this in draft for now before I dig around tomorrow and see if I've missed anything, but feel free to start reviewing at your convenience.

@martincostello
Copy link
Member Author

Failing test is EnsureConsoleLoggerOptions_ConfigureOptions_SupportsAllProperties() - I need to update the JSON console logger options to account for the new property.

- Cater for `_newLine` in JsonSerializerOptions caching.
- Lazily initialize field.
- Allow null to reset to default.
- Add assertions.
- Add/update comments.
- Use `nameof()`.
- Remove redundant field.
- Extend tests.
- Update property count to fix assertion.
- Update test to validate `NewLine` can be set/bound.
Only normalize the line endings if the `JsonWriterOptions` are not using the defaults.
@martincostello
Copy link
Member Author

I'm not sure why the Mono tests are failing - there's something in the logs about how some of the tests take a long time to run under the interpreter, so I wonder if the extra test cases I've added to the combinations for NewLine have tipped it over the edge for the 1 hour timeout?

- Access lazily initialized field through property.
- Update hash code assertion.
Use similar format string to `Format_InvalidGuidFormatSpecification`/
@martincostello
Copy link
Member Author

I'm not sure why the Mono tests are failing

Looks like these are known issues.

Reword comment as suggested.
- Simplify condition.
- Disallow null for `string NewLine` properties.
@martincostello martincostello marked this pull request as ready for review April 12, 2024 13:57
@eiriktsarpalis
Copy link
Member

I'm not sure why the Mono tests are failing

Looks like these are known issues.

We generally use the "Build Analysis" leg to determine if there any test failures that haven't been flagged as known issues.

Copy link
Member

@eiriktsarpalis eiriktsarpalis left a comment

Choose a reason for hiding this comment

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

Thanks!

@eiriktsarpalis eiriktsarpalis merged commit 6171ab5 into dotnet:main Apr 16, 2024
82 of 87 checks passed
@martincostello martincostello deleted the gh-84117-stj-jsonserializationoptions-newline branch April 16, 2024 15:47
matouskozak pushed a commit to matouskozak/runtime that referenced this pull request Apr 30, 2024
* Add new line to be specified for JSON formatting

Allow the new line string to use for indented JSON to be specified through options.
Resolves dotnet#84117.

* Address review feedback

- Cater for `_newLine` in JsonSerializerOptions caching.
- Lazily initialize field.
- Allow null to reset to default.
- Add assertions.
- Add/update comments.
- Use `nameof()`.
- Remove redundant field.
- Extend tests.

* Update Logging.Console tests

- Update property count to fix assertion.
- Update test to validate `NewLine` can be set/bound.

* Only normalize line endings if needed

Only normalize the line endings if the `JsonWriterOptions` are not using the defaults.

* Address feedback

- Access lazily initialized field through property.
- Update hash code assertion.

* Update exception message

Use similar format string to `Format_InvalidGuidFormatSpecification`/

* Address feedback

Reword comment as suggested.

* Address feedback

- Simplify condition.
- Disallow null for `string NewLine` properties.
@github-actions github-actions bot locked and limited conversation to collaborators May 17, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-System.Text.Json community-contribution Indicates that the PR has been added by a community member new-api-needs-documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[API Proposal]: Add the ability to specify line endings when serializing Json
4 participants