René's URL Explorer Experiment


Title: How do we customize serialization? · Issue #3173 · PowerShell/PowerShell · GitHub

Open Graph Title: How do we customize serialization? · Issue #3173 · PowerShell/PowerShell

X Title: How do we customize serialization? · Issue #3173 · PowerShell/PowerShell

Description: There was a PowerShell Team blog post years ago about how serialization works and how it should be possible to customize -- and of course, now I have access to all the source code, but so far I haven't been able to make extending the ser...

Open Graph Description: There was a PowerShell Team blog post years ago about how serialization works and how it should be possible to customize -- and of course, now I have access to all the source code, but so far I hav...

X Description: There was a PowerShell Team blog post years ago about how serialization works and how it should be possible to customize -- and of course, now I have access to all the source code, but so far I hav...

Opengraph URL: https://github.com/PowerShell/PowerShell/issues/3173

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"How do we customize serialization?","articleBody":"There was a [PowerShell Team blog post years ago](https://blogs.msdn.microsoft.com/powershell/2010/01/07/how-objects-are-sent-to-and-from-remote-sessions/) about how serialization works and how it should be possible to customize -- and of course, now I have access to all the source code, but so far I haven't been able to make extending the serialization work. If someone can help me figure this out, I'll make sure we get a HowTo document for future module authors out of it ...\r\n\r\nI'm going to use a simple example, but remember that I'm looking for the way to make Deserialization work **properly** -- I don't want to hear about all the workarounds for this _particular_ case (there are several). The real problem I'm trying to solve is more complicated.\r\n\r\nI need to call a remote function which takes a DateTimeOffset object, Unlike DateTime, DateTimeOffest isn't treated as a primitive type (although it should be #3172), so I want to fix that in my module.\r\n\r\n## Here's what I tried:\r\n\r\n```posh\r\nusing namespace System.Management.Automation\r\n\r\nclass DateTimeOffsetDeserializer : System.Management.Automation.PSTypeConverter {\r\n\r\n    [bool] CanConvertFrom([object]$sourceValue, [Type]$destinationType)\r\n    {\r\n        Write-Warning \"CanConvertFrom $SourceValue to $($destinationType.FullName)\"\r\n        return ([PSObject]$sourceValue).PSTypeNames.Contains(\"Deserialized.System.DateTimeOffset\")\r\n    }\r\n\r\n    [object] ConvertFrom([object]$sourceValue, [Type]$destinationType, [IFormatProvider]$formatProvider, [bool]$ignoreCase)\r\n    {\r\n        Write-Warning \"ConvertFrom $SourceValue to $($destinationType.FullName)\"\r\n        [PSObject]$psSourceValue = $sourceValue\r\n        return [DateTimeOffset]::new($psSourceValue.Ticks, $psSourceValue.Offset)\r\n    }\r\n\r\n    [bool] CanConvertTo([object]$sourceValue, [Type]$destinationType)\r\n    {\r\n        Write-Warning \"CanConvertTo $SourceValue to $($destinationType.FullName)\"\r\n        return ([PSObject]$sourceValue).PSTypeNames.Contains(\"Deserialized.System.DateTimeOffset\") -and $destinationType -eq \"System.DateTimeOffset\"\r\n    }\r\n\r\n    [object] ConvertTo([object]$sourceValue, [Type]$destinationType, [IFormatProvider]$formatProvider, [bool]$ignoreCase)\r\n    {\r\n        Write-Warning \"ConvertTo $SourceValue to $($destinationType.FullName)\"\r\n        [PSObject]$psSourceValue = $sourceValue\r\n        return [DateTimeOffset]::new($psSourceValue.Ticks, $psSourceValue.Offset)\r\n    }\r\n}\r\n\r\n# This should be enough, right?\r\nUpdate-TypeData -TypeName 'DateTimeOffset' -TargetTypeForDeserialization 'DateTimeOffsetDeserializer' -Force\r\n\r\n# I tried adding all the rest of these\r\nUpdate-TypeData -TypeName 'Deserialized.System.DateTimeOffset' -TargetTypeForDeserialization 'DateTimeOffsetDeserializer' -Force\r\nUpdate-TypeData -TypeName 'DateTimeOffset' -MemberName 'TargetTypeForDeserialization' -MemberType 'NoteProperty' -Value 'DateTimeOffsetDeserializer'\r\nUpdate-TypeData -TypeName 'Deserialized.System.DateTimeOffset' -MemberName 'TargetTypeForDeserialization' -MemberType 'NoteProperty' -Value 'DateTimeOffsetDeserializer'\r\n```\r\n\r\n\r\n### But nothing makes the this come out as a DateTimeOffset\r\n```posh\r\nusing namespace System.Management.Automation\r\n[PSSerializer]::Deserialize( [PSSerializer]::Serialize([DateTimeOffset]::Now) ).PSTypeNames\r\n```\r\n\r\n### Or make this not be \"Deserialized\"\r\n```posh\r\nInvoke-Command -ComputerName localhost { [DateTimeOffset]::Now } | % PSTypeNames\r\n```\r\n\r\n### Or make this run without crashing:\r\n```posh\r\nInvoke-Command -ComputerName localhost { param([DateTimeOffset]$Time) $Time.LocalDateTime } -Args ([DateTimeOffset]::Now)\r\n```\r\n\r\nI also tried creating the `DateTimeOffsetDeserializer` class in C#, but I think I'm misunderstanding that original blog post or something about how the registration works...","author":{"url":"https://github.com/Jaykul","@type":"Person","name":"Jaykul"},"datePublished":"2017-02-20T00:45:08Z","url":"https://github.com/PowerShell/PowerShell/issues/3173"}

react-profiling0
react-import-mapreact,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322
route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:f73ebe7e-b0af-e19a-0d90-ab816f843d23
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idD110:1B5150:3E66:53CC:6AFDD4E1
html-safe-nonce955d3e1c3d1d410cce322139ceea3795e976ac4b09dc362f57508fc97464c7cc
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEMTEwOjFCNTE1MDozRTY2OjUzQ0M6NkFGREQ0RTEiLCJ2aXNpdG9yX2lkIjoiMzQ3OTg2NjcwMzU1MzA5MDc4NSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmac1396a6ad3857cd20df223139a065fd319911923694800c8ed5891578884e0c36
hovercard-subject-tagissue:208760958
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/PowerShell/PowerShell/3173/issue_layout
twitter:imagehttps://opengraph.githubassets.com/7847ad5854f5f61e261ec0513b93b5d6a987dd2411e3f18583d88e7093fbe805/PowerShell/PowerShell/issues/3173
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/7847ad5854f5f61e261ec0513b93b5d6a987dd2411e3f18583d88e7093fbe805/PowerShell/PowerShell/issues/3173
og:image:altThere was a PowerShell Team blog post years ago about how serialization works and how it should be possible to customize -- and of course, now I have access to all the source code, but so far I hav...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernameJaykul
hostnamegithub.com
expected-hostnamegithub.com
None9918bd4004419458bcd838065ac2a76b76ebd11705d73909fff5ab99e996fa23
turbo-cache-controlno-preview
go-importgithub.com/PowerShell/PowerShell git https://github.com/PowerShell/PowerShell.git
octolytics-dimension-user_id11524380
octolytics-dimension-user_loginPowerShell
octolytics-dimension-repository_id49609581
octolytics-dimension-repository_nwoPowerShell/PowerShell
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id49609581
octolytics-dimension-repository_network_root_nwoPowerShell/PowerShell
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
releasea231c174493a6a442c0b0544475c918b30128208
ui-targetfull
theme-color#1e2327
color-schemelight dark
react-app-nameissues

Links:

Skip to contenthttps://github.com/PowerShell/PowerShell/issues/3173#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2FPowerShell%2FPowerShell%2Fissues%2F3173
GitHubRepository hosting, code review, and collaborationhttps://github.com/platform
CopilotAI coding agent for tasks, projects, and automated workhttps://github.com/features/copilot
ActionsCI/CD and automationhttps://github.com/features/actions
Code QualityQuality analysis, fixes, and enforcementhttps://github.com/features/code-quality
CodespacesCloud development environmentshttps://github.com/features/codespaces
Code SecurityVulnerability detection and remediationhttps://github.com/security/advanced-security/code-security
Secret ProtectionSecret scanning and leak preventionhttps://github.com/security/advanced-security/secret-protection
All Featureshttps://github.com/features
Documentationhttps://docs.github.com/en
Traininghttps://learn.github.com/skills
Certificationshttps://learn.github.com/credentials
Build with Copilothttps://github.com/features/ai
Customize Copilothttps://docs.github.com/en/copilot/how-tos/copilot-on-github/customize-copilot/customize-copilot-overview
Integrationshttps://github.com/marketplace
Trending reposhttps://github.com/trending
GitHub Sponsorshttps://github.com/open-source/sponsors
Developer articleshttps://github.com/resources/articles
ChangelogYour source for the latest features, improvements, and fixes across GitHub products, all in one place.https://github.blog/changelog/
Enterpriseshttps://github.com/enterprise
Teamhttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
See all industrieshttps://github.com/solutions/industry
Why GitHubhttps://github.com/why-github
Customer Storieshttps://github.com/customer-stories
Business insightshttps://github.com/solutions/executive-insights
Trust Centerhttps://github.com/trust-center
GitHub Advanced SecurityEnterprise-grade code securityhttps://github.com/security/advanced-security
Copilot for businessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Documentationhttps://docs.github.com/en
Resource centerhttps://github.com/resources
Bloghttps://github.blog/
Events & webinarshttps://github.com/resources/events
Community Forumhttps://github.com/orgs/community/discussions
Customer Storieshttps://github.com/customer-stories
Integrationshttps://github.com/marketplace
Customer supporthttps://help.github.com/
Traininghttps://learn.github.com/skills
GitHub Statushttps://www.githubstatus.com/
Abouthttps://github.com/about
Partnershttps://github.com/partners
Changeloghttps://github.blog/changelog/
GitHub UniverseThe event for developers, by developers — talks, workshops, and what’s next for GitHub.https://githubuniverse.com/
Pricinghttps://github.com/pricing
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2FPowerShell%2FPowerShell%2Fissues%2F3173
Sign uphttps://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=PowerShell%2FPowerShell
Reloadhttps://github.com/PowerShell/PowerShell/issues/3173
Reloadhttps://github.com/PowerShell/PowerShell/issues/3173
Reloadhttps://github.com/PowerShell/PowerShell/issues/3173
PowerShellhttps://github.com/PowerShell
PowerShellhttps://github.com/PowerShell/PowerShell
Codehttps://github.com/PowerShell/PowerShell
Issues1.3k (1.3k)https://github.com/PowerShell/PowerShell/issues
Pull requests366 (366)https://github.com/PowerShell/PowerShell/pulls
Discussionshttps://github.com/PowerShell/PowerShell/discussions
Actionshttps://github.com/PowerShell/PowerShell/actions
Projectshttps://github.com/PowerShell/PowerShell/projects
Security and quality3 (3)https://github.com/PowerShell/PowerShell/security
Insightshttps://github.com/PowerShell/PowerShell/insights
https://github.com/PowerShell/PowerShell
New issuehttps://github.com/login?return_to=https://github.com/PowerShell/PowerShell/issues/3173
New issuehttps://github.com/login?return_to=https://github.com/PowerShell/PowerShell/issues/3173
How do we customize serialization?https://github.com/PowerShell/PowerShell/issues/3173#top
Issue-BugIssue has been identified as a bug in the producthttps://github.com/PowerShell/PowerShell/issues?q=state%3Aopen%20label%3A%22Issue-Bug%22
Resolution-No ActivityIssue has had no activity for 6 months or morehttps://github.com/PowerShell/PowerShell/issues?q=state%3Aopen%20label%3A%22Resolution-No%20Activity%22
WG-Enginecore PowerShell engine, interpreter, and runtimehttps://github.com/PowerShell/PowerShell/issues?q=state%3Aopen%20label%3A%22WG-Engine%22
WG-RemotingPSRP issues with any transport layerhttps://github.com/PowerShell/PowerShell/issues?q=state%3Aopen%20label%3A%22WG-Remoting%22
https://github.com/Jaykul
Joel Bennett (Jaykul)https://github.com/Jaykul
on Feb 20, 2017https://github.com/PowerShell/PowerShell/issues/3173#issue-208760958
PowerShell Team blog post years agohttps://blogs.msdn.microsoft.com/powershell/2010/01/07/how-objects-are-sent-to-and-from-remote-sessions/
#3172https://github.com/PowerShell/PowerShell/issues/3172
https://github.com/Jaykul
Joel Bennett (Jaykul)https://github.com/Jaykul
on Feb 22, 2017https://github.com/PowerShell/PowerShell/issues/3173#issuecomment-281557119
the blog posthttps://blogs.msdn.microsoft.com/powershell/2010/01/07/how-objects-are-sent-to-and-from-remote-sessions/
https://github.com/iSazonov
Ilya (iSazonov)https://github.com/iSazonov
on Feb 22, 2017https://github.com/PowerShell/PowerShell/issues/3173#issuecomment-281617017
Joel Bennett (@Jaykul)https://github.com/Jaykul
https://github.com/PowerShell/PowerShell-Docshttps://github.com/PowerShell/PowerShell-Docs
https://github.com/Jaykul
Joel Bennett (Jaykul)https://github.com/Jaykul
on Feb 22, 2017https://github.com/PowerShell/PowerShell/issues/3173#issuecomment-281768987
Jason Shirk (@lzybkr)https://github.com/lzybkr
https://github.com/lzybkr
Jason Shirk (lzybkr)https://github.com/lzybkr
on Feb 23, 2017https://github.com/PowerShell/PowerShell/issues/3173#issuecomment-281847067
Jason Shirk (lzybkr)https://github.com/lzybkr
WG-Enginecore PowerShell engine, interpreter, and runtimehttps://github.com/PowerShell/PowerShell/issues?q=state%3Aopen%20label%3A%22WG-Engine%22
WG-RemotingPSRP issues with any transport layerhttps://github.com/PowerShell/PowerShell/issues?q=state%3Aopen%20label%3A%22WG-Remoting%22
Issue-BugIssue has been identified as a bug in the producthttps://github.com/PowerShell/PowerShell/issues?q=state%3Aopen%20label%3A%22Issue-Bug%22
on Feb 23, 2017https://github.com/PowerShell/PowerShell/issues/3173#event-973554346
https://github.com/Jaykul
Joel Bennett (Jaykul)https://github.com/Jaykul
on Feb 23, 2017https://github.com/PowerShell/PowerShell/issues/3173#issuecomment-281867375
https://github.com/Brain2000
Brain2000 (Brain2000)https://github.com/Brain2000
on Dec 20, 2018https://github.com/PowerShell/PowerShell/issues/3173#issuecomment-448847872
https://github.com/SSvilen
Svilen (SSvilen)https://github.com/SSvilen
on Jun 10, 2019https://github.com/PowerShell/PowerShell/issues/3173#issuecomment-500578797
Paul Higinbotham (@PaulHigin)https://github.com/PaulHigin
Joel Bennett (@Jaykul)https://github.com/Jaykul
https://github.com/PaulHigin
Paul Higinbotham (PaulHigin)https://github.com/PaulHigin
on Jun 18, 2019https://github.com/PowerShell/PowerShell/issues/3173#issuecomment-503242900
Svilen (@SSvilen)https://github.com/SSvilen
https://github.com/kenny1983
kenny1983https://github.com/kenny1983
on Oct 20, 2019https://github.com/PowerShell/PowerShell/issues/3173#issuecomment-544232925
https://github.com/Kagre
Kagrehttps://github.com/Kagre
on Mar 10, 2021https://github.com/PowerShell/PowerShell/issues/3173#issuecomment-794683881
https://github.com/Kagre
Kagrehttps://github.com/Kagre
on Mar 10, 2021https://github.com/PowerShell/PowerShell/issues/3173#issuecomment-795872817
https://github.com/1ramnik
1ramnikhttps://github.com/1ramnik
on Mar 10, 2021https://github.com/PowerShell/PowerShell/issues/3173#issuecomment-795889788
https://github.com/Kagre
Kagrehttps://github.com/Kagre
on Mar 10, 2021https://github.com/PowerShell/PowerShell/issues/3173#issuecomment-795904149
https://github.com/Kagre
Kagrehttps://github.com/Kagre
on Mar 10, 2021https://github.com/PowerShell/PowerShell/issues/3173#issuecomment-796278030
https://github.com/Stroniax
Caleb Frederickson (Stroniax)https://github.com/Stroniax
on Jul 12, 2023https://github.com/PowerShell/PowerShell/issues/3173#issuecomment-1633056428
the blog posthttps://blogs.msdn.microsoft.com/powershell/2010/01/07/how-objects-are-sent-to-and-from-remote-sessions/
microsoft-github-policy-servicehttps://github.com/apps/microsoft-github-policy-service
Resolution-No ActivityIssue has had no activity for 6 months or morehttps://github.com/PowerShell/PowerShell/issues?q=state%3Aopen%20label%3A%22Resolution-No%20Activity%22
on Jan 9, 2024https://github.com/PowerShell/PowerShell/issues/3173#event-11424861875
https://github.com/apps/microsoft-github-policy-service
microsoft-github-policy-servicehttps://github.com/apps/microsoft-github-policy-service
on Jan 9, 2024https://github.com/PowerShell/PowerShell/issues/3173#issuecomment-1882374963
Microsoft GitHub Policy Servicehttps://aka.ms/1es-gitops
https://github.com/apps/microsoft-github-policy-service
microsoft-github-policy-servicehttps://github.com/apps/microsoft-github-policy-service
on Jan 9, 2024https://github.com/PowerShell/PowerShell/issues/3173#issuecomment-1882374965
Microsoft GitHub Policy Servicehttps://aka.ms/1es-gitops
microsoft-github-policy-servicehttps://github.com/apps/microsoft-github-policy-service
completedhttps://github.com/PowerShell/PowerShell/issues?q=is%3Aissue%20state%3Aclosed%20archived%3Afalse%20reason%3Acompleted
on Jan 16, 2024https://github.com/PowerShell/PowerShell/issues/3173#event-11498400376
Sign up for freehttps://github.com/signup?return_to=https://github.com/PowerShell/PowerShell/issues/3173
Sign in to commenthttps://github.com/login?return_to=https://github.com/PowerShell/PowerShell/issues/3173
Issue-BugIssue has been identified as a bug in the producthttps://github.com/PowerShell/PowerShell/issues?q=state%3Aopen%20label%3A%22Issue-Bug%22
Resolution-No ActivityIssue has had no activity for 6 months or morehttps://github.com/PowerShell/PowerShell/issues?q=state%3Aopen%20label%3A%22Resolution-No%20Activity%22
WG-Enginecore PowerShell engine, interpreter, and runtimehttps://github.com/PowerShell/PowerShell/issues?q=state%3Aopen%20label%3A%22WG-Engine%22
WG-RemotingPSRP issues with any transport layerhttps://github.com/PowerShell/PowerShell/issues?q=state%3Aopen%20label%3A%22WG-Remoting%22
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.