I have a problem in my C# Web API, where an action is return an object with DateTime property. However, when receiving it and converting it to PS object with ConvertFrom-Json the DateTime property is converted to a string.
I then began testing a bit and found it curious how JSON serialize DateTime in Powershell:
This gives me:
I thought I would be genius just to do this then:
I could ofcourse do this then:
But why oh why?
I'd call this a bug in ConvertTo-Json. It should be treating DateTime as a primitive type and not appending any of the extra ETS properties. (The same can be said for any other primitive type that JSON supports, but as far as I know, none of the other ones have extra properties tacked on by PowerShell's type system).
You can report the bug over on UserVoice: https://windowsserver.uservoice.com/forums/301869-powershell/category/148044-powershell-engine
I guess I don't understand the value added by creating a new object of an object. Does this get you what you were expecting?
$object = Get-Date
Bob, no sorry.
Maybe this is more a C# question?
public class Test
What I get return:
Name MemberType Definition
I would have thought that TestDate would be a DateTime and not string..
You must be logged in to reply to this topic.