Skip to content

Commit 6dc6f1e

Browse files
jborean93sdwheeler
authored andcommitted
Document PSSerializeJSONLongEnumAsNumber
Documents the new experiemental feature PSSerializeJSONLongEnumAsNumber that aligns the serialization behaviour of enums based on long/ulong with the other base types.
1 parent 5e0cfbf commit 6dc6f1e

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

reference/docs-conceptual/learn/experimental-features.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ PSCommandWithArgs False PSEngine Enable `-CommandWithArgs` para
4040
PSFeedbackProvider True PSEngine Replace the hard-coded suggestion framework with …
4141
PSLoadAssemblyFromNativeCode False PSEngine Expose an API to allow assembly loading from nati…
4242
PSModuleAutoLoadSkipOfflineFiles True PSEngine Module discovery will skip over files that are ma…
43+
PSSerializeJSONLongEnumAsNumber True PSEngine Serialize enums based on long or ulong as an nume…
4344
PSSubsystemPluginModel True PSEngine A plugin model for registering and un-registering…
4445
```
4546

@@ -95,6 +96,8 @@ Legend
9596
| [PSModuleAutoLoadSkipOfflineFiles][17] | | | ![Experimental][02] | ![Experimental][02] |
9697
| [PSCommandWithArgs][11] | | | ![Experimental][02] | ![Experimental][02] |
9798
| [PSNativeWindowsTildeExpansion][22] | | | | ![Experimental][02] |
99+
| [PSCustomTableHeaderLabelDecoration][13] | | | ![Mainstream][01] | |
100+
| [PSSerializeJSONLongEnumAsNumber][24] | | | | ![Experimental][02] |
98101

99102
### PSAnsiRenderingFileInfo
100103

@@ -364,6 +367,36 @@ This feature only applies to Windows. On non-Windows platforms, tilde expansion
364367

365368
This feature was added in PowerShell 7.5-preview.2.
366369

370+
### PSSerializeJSONLongEnumAsNumber
371+
372+
This feature enables the cmdlet [ConvertTo-Json][33] to serialize any enum values based on
373+
`Int64/long` or `UInt64/ulong` as a numeric value rather than the string representation of that
374+
enum value. This aligns the behaviour of enum serialization with other enum base types where the
375+
cmdlet serializes enums as their numeric value. The `-EnumsAsStrings` parameter can use the previous
376+
behaviour to serialize as the string representation.
377+
378+
For example:
379+
380+
```powershell
381+
# PSSerializeJSONLongEnumAsNumber disabled
382+
@{
383+
Key = [System.Management.Automation.Tracing.PowerShellTraceKeywords]::Cmdlets
384+
} | ConvertTo-Json
385+
# { "Key": "Cmdlets" }
386+
387+
# PSSerializeJSONLongEnumAsNumber enabled
388+
@{
389+
Key = [System.Management.Automation.Tracing.PowerShellTraceKeywords]::Cmdlets
390+
} | ConvertTo-Json
391+
# { "Key": 32 }
392+
393+
# -EnumsAsStrings to revert back to the old behaviour
394+
@{
395+
Key = [System.Management.Automation.Tracing.PowerShellTraceKeywords]::Cmdlets
396+
} | ConvertTo-Json -EnumsAsStrings
397+
# { "Key": "Cmdlets" }
398+
```
399+
367400
<!-- link references -->
368401
[01]: ../../media/shared/check-mark-button-2705.svg
369402
[02]: ../../media/shared/construction-sign-1f6a7.svg
@@ -385,6 +418,7 @@ This feature was added in PowerShell 7.5-preview.2.
385418
[21]: #psnativepspathresolution
386419
[22]: #psnativewindowstildeexpansion
387420
[23]: #pssubsystempluginmodel
421+
[24]: #psserializejsonlongenumasnumber
388422
[25]: https://github.com/PowerShell/PowerShell/issues/new/choose
389423
[26]: https://github.com/PowerShell/PowerShell/tree/master/test/tools/TestExe
390424
[27]: xref:Microsoft.PowerShell.Core.Disable-ExperimentalFeature

0 commit comments

Comments
 (0)