|
@@ -1,4 +1,6 @@
|
|
|
-using System.Text.Json;
|
|
|
+using System;
|
|
|
+using System.Text.Json;
|
|
|
+using Vinno.IUS.Common.Log;
|
|
|
|
|
|
namespace Vinno.FIS.Sonopost.Helpers
|
|
|
{
|
|
@@ -16,8 +18,9 @@ namespace Vinno.FIS.Sonopost.Helpers
|
|
|
{
|
|
|
return JsonSerializer.Serialize(obj, options);
|
|
|
}
|
|
|
- catch
|
|
|
+ catch (Exception ex)
|
|
|
{
|
|
|
+ Logger.WriteLineError($"JsonHelper To Json {obj} Error:{ex}");
|
|
|
return string.Empty;
|
|
|
}
|
|
|
}
|
|
@@ -39,8 +42,33 @@ namespace Vinno.FIS.Sonopost.Helpers
|
|
|
{
|
|
|
return JsonSerializer.Deserialize<T>(jsonStr, options);
|
|
|
}
|
|
|
- catch
|
|
|
+ catch (Exception ex)
|
|
|
{
|
|
|
+ Logger.WriteLineError($"JsonHelper JsonToObj {jsonStr} Error:{ex}");
|
|
|
+ return default;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// convert json to object
|
|
|
+ /// </summary>
|
|
|
+ /// <typeparam name="T"></typeparam>
|
|
|
+ /// <param name="jsonStr"></param>
|
|
|
+ /// <param name="options"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ public static object JsonToObj(string jsonStr, Type type, JsonSerializerOptions options = null)
|
|
|
+ {
|
|
|
+ if (string.IsNullOrWhiteSpace(jsonStr))
|
|
|
+ {
|
|
|
+ return default;
|
|
|
+ }
|
|
|
+ try
|
|
|
+ {
|
|
|
+ return JsonSerializer.Deserialize(jsonStr, type, options);
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ Logger.WriteLineError($"JsonHelper JsonToObj {jsonStr} Error:{ex}");
|
|
|
return default;
|
|
|
}
|
|
|
}
|