Skip to content

Commit

Permalink
Json Serialization Demo
Browse files Browse the repository at this point in the history
  • Loading branch information
ninmonkey committed Jan 19, 2024
1 parent 9857660 commit b10505a
Showing 1 changed file with 12 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ As a base case, automatically serialize all properties (if able to)
'@

class Forecast {
[datetime]$Date
[int]$Degrees
[string]$Summary
[datetime] $Date
[int] $Degrees
[string] $Summary
}

[Forecast]$CastObj = @{
Expand Down Expand Up @@ -74,16 +74,20 @@ class SimpleProcess {

[Datetime]$When

# a property that normally errors out:
# a property that normally errors out (with default serialization)
[System.Text.Json.Serialization.JsonIgnoreAttribute()]
[Diagnostics.ProcessModuleCollection]$Modules
# $Modules = 0..10

# and a property to only ignore when null
[object]$MaybeData

SimpleProcess ( ) {
$This.When = Get-Date
$This.When = Get-Date
$this.MaybeData = $Null
}
SimpleProcess ( [object]$Other ) {
$this.When = Get-Date
$this.MaybeData = $Null
$This.CommandLine = ($Other)?.CommandLine ?? ''
$This.Modules = ($Other)?.Modules
# $this.Modules = ($Other)?.Modules
Expand All @@ -92,6 +96,8 @@ class SimpleProcess {
}
}

[SimpleProcess]@(ps | s -first 1 )
return
[List[Object]]$Records = @(
# class coerce from an object
[SimpleProcess](get-process pwsh | s -First 1)
Expand Down

0 comments on commit b10505a

Please sign in to comment.