{"id":582,"date":"2022-11-21T13:51:04","date_gmt":"2022-11-21T04:51:04","guid":{"rendered":"https:\/\/sumomo.ohwaki.jp\/wordpress\/?p=582"},"modified":"2022-11-21T13:51:53","modified_gmt":"2022-11-21T04:51:53","slug":"net7%e3%81%aejson%e3%82%b7%e3%83%aa%e3%82%a2%e3%83%a9%e3%82%a4%e3%82%b6","status":"publish","type":"post","link":"https:\/\/sumomo.ohwaki.jp\/wordpress\/?p=582","title":{"rendered":".NET7\u306eJSON\u30b7\u30ea\u30a2\u30e9\u30a4\u30b6"},"content":{"rendered":"\n<p>.NET7\u306b\u306a\u3063\u3066\u3001JSON\u30b7\u30ea\u30a2\u30e9\u30a4\u30b6\u304c\u30a2\u30c3\u30d7\u30c7\u30fc\u30c8\u3055\u308c\u3001\u4eca\u307e\u3067\u30b5\u30dd\u30fc\u30c8\u3057\u3066\u3044\u306a\u304b\u3063\u305fDateOnly\u578b\u3084TimeOnly\u5f62\u306e\u5909\u63db\u3092\u884c\u3063\u3066\u304f\u308c\u308b\u3088\u3046\u306b\u306a\u3063\u305f\u3002<\/p>\n\n\n\n<p>.NET6\u3068.NET7\u3092\u6bd4\u3079\u308b\u3068\u4ee5\u4e0b\u306e\u3088\u3046\u611f\u3058\u3002(dotnet-script\u3067\u5b9f\u884c)<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism undefined-numbers lang-csharp\" data-file=\"\u30b7\u30ea\u30a2\u30e9\u30a4\u30ba\" data-lang=\"C#\"><code>using System.Text.Json;\npublic class Person {\n  public string Name { get; set; }\n  public DateOnly Birthday { get; set; }\n}\nList&lt;Person&gt; plst = new();\nPerson p = new() { Name=&quot;T.Sumomo&quot;, Birthday=new DateOnly(1964,2,3)};\nplst.Add(p);\np = new() { Name=&quot;J.Sumomo&quot;, Birthday=new DateOnly(1988,5,13)};\nplst.Add(p);\nstring json = JsonSerializer.Serialize(plst);\njson<\/code><\/pre><\/div>\n\n\n\n<p>\u7d50\u679c(.NET6)<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism undefined-numbers lang-bash\" data-file=\".NET6 \u7d50\u679c\" data-lang=\"Bash\"><code>System.NotSupportedException: System.NotSupportedException: Serialization and deserialization of &#39;System.DateOnly&#39; instances are not supported. Path: $.Birthday.\n  + System.Text.Json.ThrowHelper.ThrowNotSupportedException(ref System.Text.Json.WriteStack, System.NotSupportedException)\n  + JsonConverter&lt;T&gt;.WriteCore(System.Text.Json.Utf8JsonWriter, ref T, System.Text.Json.JsonSerializerOptions, ref System.Text.Json.WriteStack)\n  + System.Text.Json.JsonSerializer.WriteUsingSerializer&lt;TValue&gt;(System.Text.Json.Utf8JsonWriter, ref TValue, System.Text.Json.Serialization.Metadata.JsonTypeInfo)\n  + System.Text.Json.JsonSerializer.WriteStringUsingSerializer&lt;TValue&gt;(ref TValue, System.Text.Json.Serialization.Metadata.JsonTypeInfo)\n  + System.Text.Json.JsonSerializer.Serialize&lt;TValue&gt;(TValue, System.Text.Json.JsonSerializerOptions)<\/code><\/pre><\/div>\n\n\n\n<p>DateOnly\u306e\u30b7\u30ea\u30a2\u30e9\u30a4\u30ba\u30fb\u30c7\u30b7\u30ea\u30a2\u30e9\u30a4\u30ba\u3092\u30b5\u30dd\u30fc\u30c8\u3057\u3066\u3044\u306a\u3044\u306e\u3067\u3001\u30a8\u30e9\u30fc<\/p>\n\n\n\n<p>\u7d50\u679c(.NET7)<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism undefined-numbers lang-json\" data-file=\".NET7 \u7d50\u679c\" data-lang=\"JSON\"><code>&quot;[{\\&quot;Name\\&quot;:\\&quot;T.Sumomo\\&quot;,\\&quot;Birthday\\&quot;:\\&quot;1964-02-03\\&quot;},{\\&quot;Name\\&quot;:\\&quot;J.Sumomo\\&quot;,\\&quot;Birthday\\&quot;:\\&quot;1988-11-23\\&quot;}]&quot;<\/code><\/pre><\/div>\n\n\n\n<p>DateOnly\u306e\u30b7\u30ea\u30a2\u30e9\u30a4\u30ba\u30fb\u30c7\u30b7\u30ea\u30a2\u30e9\u30a4\u30ba\u3092\u30b5\u30dd\u30fc\u30c8\u3057\u305f\u306e\u3067\u3001\u6b63\u5e38\u306bJSON\u306b\u30b7\u30ea\u30a2\u30e9\u30a4\u30ba\u3055\u308c\u308b\u3002<\/p>\n\n\n\n<p>\u3082\u3061\u308d\u3093\u3001\u30c7\u30b7\u30ea\u30a2\u30e9\u30a4\u30ba\u3082OK<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism undefined-numbers lang-csharp\" data-file=\"\u30c7\u30b7\u30ea\u30a2\u30e9\u30a4\u30ba\" data-lang=\"C#\"><code>var xlst = JsonSerializer.Deserialize&lt;List&lt;Person&gt;&gt;(json);\nxlst<\/code><\/pre><\/div>\n\n\n\n<p>\u7d50\u679c<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism undefined-numbers lang-bash\" data-file=\"\u30c7\u30b7\u30ea\u30a2\u30e9\u30a4\u30ba\u7d50\u679c\" data-lang=\"Bash\"><code>List&lt;Submission#1.Person&gt;(2) { Submission#1.Person { Birthday=[1964\/02\/03], Name=&quot;T.Sumomo&quot; }, Submission#1.Person { Birthday=[1988\/11\/23], Name=&quot;J.Sumomo&quot; } }<\/code><\/pre><\/div>\n\n\n\n<p>\u5927\u3057\u305f\u5909\u66f4\u3067\u306f\u306a\u3044\u304c\u3001\u7d50\u69cb\u3042\u308a\u304c\u305f\u3044\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>.NET7\u306b\u306a\u3063\u3066\u3001JSON\u30b7\u30ea\u30a2\u30e9\u30a4\u30b6\u304c\u30a2\u30c3\u30d7\u30c7\u30fc\u30c8\u3055\u308c\u3001\u4eca\u307e\u3067\u30b5\u30dd\u30fc\u30c8\u3057\u3066\u3044 &hellip; <a href=\"https:\/\/sumomo.ohwaki.jp\/wordpress\/?p=582\">\u7d9a\u304d\u3092\u8aad\u3080 <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[18,9,4],"tags":[],"class_list":["post-582","post","type-post","status-publish","format-standard","hentry","category-net","category-c","category-4"],"_links":{"self":[{"href":"https:\/\/sumomo.ohwaki.jp\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/582","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/sumomo.ohwaki.jp\/wordpress\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sumomo.ohwaki.jp\/wordpress\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sumomo.ohwaki.jp\/wordpress\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/sumomo.ohwaki.jp\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=582"}],"version-history":[{"count":5,"href":"https:\/\/sumomo.ohwaki.jp\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/582\/revisions"}],"predecessor-version":[{"id":587,"href":"https:\/\/sumomo.ohwaki.jp\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/582\/revisions\/587"}],"wp:attachment":[{"href":"https:\/\/sumomo.ohwaki.jp\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=582"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sumomo.ohwaki.jp\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=582"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sumomo.ohwaki.jp\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=582"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}