序列化设置

Uat_Study
hang 2022-05-09 11:10:25 +08:00
parent 90ff700aa4
commit 4eecbe1095
5 changed files with 25 additions and 11 deletions

View File

@ -1,6 +1,7 @@

using Microsoft.Extensions.DependencyInjection;
using Newtonsoft.Json;
using System;
namespace IRaCIS.Core.API
{
@ -41,6 +42,18 @@ namespace IRaCIS.Core.API
});
Newtonsoft.Json.JsonSerializerSettings setting = new Newtonsoft.Json.JsonSerializerSettings();
JsonConvert.DefaultSettings = new Func<JsonSerializerSettings>(() =>
{
//日期类型默认格式化处理
setting.DateFormatString = "yyyy-MM-dd HH:mm:ss";
setting.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;
return setting;
});
}
}
}

View File

@ -36,7 +36,7 @@ namespace IRaCIS.Core.Application.Filter
else
{
context.Result = new JsonResult(ResponseOutput.NotOk(" Program exception, please contact the developer! " + (context.Exception.InnerException is null ? (context.Exception.Message /*+ context.Exception.StackTrace*/)
: (context.Exception.InnerException?.Message /*+ context.Exception.InnerException?.StackTrace*/)) ), ApiResponseCodeEnum.ProgramException);
: (context.Exception.InnerException?.Message /*+ context.Exception.InnerException?.StackTrace*/)), ApiResponseCodeEnum.ProgramException));
}

View File

@ -17,12 +17,13 @@ namespace IRaCIS.Core.Domain.Common
/// <returns></returns>
public static string ToJcJson(this object obj)
{
JsonSerializerSettings settings = new JsonSerializerSettings();
settings.PreserveReferencesHandling = PreserveReferencesHandling.Objects;
settings.ReferenceLoopHandling = ReferenceLoopHandling.Serialize;
return JsonConvert.SerializeObject(obj, settings);
//JsonSerializerSettings settings = new JsonSerializerSettings();
//settings.PreserveReferencesHandling = PreserveReferencesHandling.Objects;
//settings.ReferenceLoopHandling = ReferenceLoopHandling.Serialize;
//return JsonConvert.SerializeObject(obj, settings);
//return JsonSerializer.Serialize(obj);
return JsonConvert.SerializeObject(obj);
}
}
}

View File

@ -295,8 +295,8 @@ namespace IRaCIS.Core.Infra.EFCore.Common
var entity = data.Entity as T;
inspection = f(entity);
}
inspection.Identification = $"{GetRequestUrl()}/{ data.Entity.GetType().ToString().Substring(data.Entity.GetType().ToString().LastIndexOf('.') + 1)}/{type}";
var originaldata = data.OriginalValues as T;
inspection.Identification = $"{_userInfo.RequestUrl}/{ data.Entity.GetType().Name}/{type}";
var originaldata = data.OriginalValues.ToObject();
if (originaldata != null)
{
inspection.LastJsonDetail = originaldata.ToJcJson();