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-Json
Expected 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.
Any reason why
hiddenhas no bearing onConvertTo-Json? Seems thatGet-Memberhonors visibility, but JSON serialization does not.Steps to reproduce
Expected behavior
Actual behavior
Environment data
FWIW, Appears
ConvertTo-Xml -As "String"does honor visibility:Also, did see #6652 and there's some mention re: hidden with regards to format-* but didn't see anythign related to JSON serialization.