-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Closed
Labels
Issue-BugIssue has been identified as a bug in the productIssue has been identified as a bug in the productResolution-No ActivityIssue has had no activity for 6 months or moreIssue has had no activity for 6 months or moreWG-Enginecore PowerShell engine, interpreter, and runtimecore PowerShell engine, interpreter, and runtime
Description
Any reason why hidden has no bearing on ConvertTo-Json? Seems that Get-Member honors visibility, but JSON serialization does not.
Steps to reproduce
Class Person {
hidden [string] $FirstName
hidden [string] $LastName
[string] $FullName
Person([string]$First, [string]$Last) {
$this.FirstName = $First
$this.LastName = $Last
$this.FullName = $First, $Last -join " "
}
[string] ToString() {
Return $this.FullName
}
}
$jDoe = [Person]::new("John", "Doe")
Write-Output "`nProperties:"
$jDoe | Get-Member -MemberType "Property" | Format-Table "Name", "MemberType"
Write-Output "`nJSON:"
$jDoe | ConvertTo-JsonExpected behavior
Properties:
Name MemberType
---- ----------
FullName Property
JSON:
{
"FullName": "John Doe"
}
Actual behavior
Properties:
Name MemberType
---- ----------
FullName Property
JSON:
{
"FirstName": "John",
"LastName": "Doe",
"FullName": "John Doe"
}
Environment data
Name Value
---- -----
PSVersion 6.2.1
PSEdition Core
GitCommitId 6.2.1
OS Microsoft Windows 10.0.17134
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
FWIW, Appears ConvertTo-Xml -As "String" does honor visibility:
<?xml version="1.0" encoding="utf-8"?>
<Objects>
<Object Type="Person">
<Property Name="FullName" Type="System.String">John Doe</Property>
</Object>
</Objects>
Also, did see #6652 and there's some mention re: hidden with regards to format-* but didn't see anythign related to JSON serialization.
mklement0, SeeminglyScience, agowa and clowa
Metadata
Metadata
Assignees
Labels
Issue-BugIssue has been identified as a bug in the productIssue has been identified as a bug in the productResolution-No ActivityIssue has had no activity for 6 months or moreIssue has had no activity for 6 months or moreWG-Enginecore PowerShell engine, interpreter, and runtimecore PowerShell engine, interpreter, and runtime