• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
Aucun tag

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

Commit MetaInfo

Révision23eee2ea2ae6250c06bbf5b88be02afbb74887f3 (tree)
l'heure2022-08-06 13:19:07
Auteuryoshy <yoshy.org.bitbucket@gz.j...>
Commiteryoshy

Message de Log

[MOD] DeserializeJson で入力値が空の場合に null を返すように修正
[MOD] DeserializeJson で変換時に例外が発生した場合に null を返すように修正

Change Summary

Modification

--- a/Core/Converter/JsonHelper.cs
+++ b/Core/Converter/JsonHelper.cs
@@ -1,4 +1,5 @@
1-using System.Text.Json;
1+using NLog;
2+using System.Text.Json;
23
34 namespace CleanAuLait.Core.Converter
45 {
@@ -24,6 +25,8 @@ namespace CleanAuLait.Core.Converter
2425 #else
2526 public static class JsonHelper
2627 {
28+ private static readonly ILogger logger = LogManager.GetCurrentClassLogger();
29+
2730 public static string ToJsonString<T>(this T data)
2831 {
2932 return JsonSerializer.Serialize(data);
@@ -31,7 +34,21 @@ namespace CleanAuLait.Core.Converter
3134
3235 public static T DeserializeJson<T>(this string json)
3336 {
34- return JsonSerializer.Deserialize<T>(json);
37+ T obj = default;
38+
39+ try
40+ {
41+ if (!string.IsNullOrEmpty(json))
42+ {
43+ obj = JsonSerializer.Deserialize<T>(json);
44+ }
45+ }
46+ catch (Exception e)
47+ {
48+ logger.Error(e, "json deserialization failed.");
49+ }
50+
51+ return obj;
3552 }
3653 }
3754 #endif