-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Added support for converting enums as strings in JSON #4318
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -211,6 +211,23 @@ Describe "Json Tests" -Tags "Feature" { | |
| $emptyStringResult = ConvertFrom-Json "" | ||
| $emptyStringResult | Should Be $null | ||
| } | ||
|
|
||
| It "Convert enumerated values to Json" { | ||
|
|
||
| $sampleObject = [pscustomobject]@{ | ||
| PSTypeName = 'Test.EnumSample' | ||
| SampleSimpleEnum = [System.Management.Automation.ActionPreference]::Ignore | ||
| SampleBitwiseEnum = [System.Management.Automation.CommandTypes]'Alias,Function,Cmdlet' | ||
| } | ||
|
|
||
| $response4 = ConvertTo-Json -InputObject $sampleObject -Compress | ||
| $response4 | Should Be '{"SampleSimpleEnum":4,"SampleBitwiseEnum":11}' | ||
|
|
||
| $response4 = ConvertTo-Json -InputObject $sampleObject -Compress -EnumsAsStrings | ||
| $response4 | Should Be '{"SampleSimpleEnum":"Ignore","SampleBitwiseEnum":"Alias, Function, Cmdlet"}' | ||
|
|
||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please remove extra line. |
||
| } | ||
|
|
||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please remove extra line. |
||
| } | ||
|
|
||
| Context "JsonObject Tests" { | ||
|
|
@@ -1458,9 +1475,9 @@ Describe "Json Bug fixes" -Tags "Feature" { | |
| It "ConvertFrom-Json deserializes an array of PSObjects (in multiple lines) as a single string." { | ||
|
|
||
| # Create an array of PSCustomObjects, and serialize it | ||
| $array = [pscustomobject]@{ objectName = "object1Name"; objectValue = "object1Value" }, | ||
| [pscustomobject]@{ objectName = "object2Name"; objectValue = "object2Value" } | ||
| $array = [pscustomobject]@{ objectName = "object1Name"; objectValue = "object1Value" }, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unintended whitespace change?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes. But I believe this is because the source newlines were inconsistent. I didn't apply any changes here nor in the next one. IMHO better for newlines to be consistent than to have to manually reset them when tooling does the right thing. |
||
| [pscustomobject]@{ objectName = "object2Name"; objectValue = "object2Value" } | ||
|
|
||
| # Serialize the array to a text file | ||
| $filePath = Join-Path $TESTDRIVE test.json | ||
| $array | ConvertTo-Json | Out-File $filePath -Encoding utf8 | ||
|
|
@@ -1472,7 +1489,7 @@ Describe "Json Bug fixes" -Tags "Feature" { | |
|
|
||
| It "ConvertFrom-Json deserializes an array of strings (in multiple lines) as a single string." { | ||
|
|
||
| $result = "[1,","2,","3]" | ConvertFrom-Json | ||
| $result = "[1,","2,","3]" | ConvertFrom-Json | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unintended whitespace change?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same reply as above. I did not make these changes, and believe them to be due to inconsistent newlines. My recommendation is to accept the change to make newlines consistent so that future changes in this file don't run into the same issue. |
||
| $result.Count | Should be 3 | ||
| } | ||
| } | ||
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.
Please correct typo gets -> Gets.