mirror of
https://gitee.com/langsisi_admin/serein-flow
synced 2026-03-03 00:00:49 +08:00
修复了已知的bug
This commit is contained in:
@@ -4,9 +4,25 @@ namespace Serein.Extend.NewtonsoftJson
|
||||
{
|
||||
public static class NewtonsoftJsonExtend
|
||||
{
|
||||
/// <summary>
|
||||
/// 对象转 Json 文本
|
||||
/// </summary>
|
||||
/// <param name="data"></param>
|
||||
/// <returns></returns>
|
||||
public static string ToJsonText(this object data)
|
||||
{
|
||||
return JsonHelper.Serialize(data);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Json 文本转对象
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="jsonText"></param>
|
||||
/// <returns></returns>
|
||||
public static T ToJsonObject<T>(this string jsonText) where T : class
|
||||
{
|
||||
return JsonHelper.Deserialize<T>(jsonText);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,11 +7,6 @@ using System.Diagnostics.CodeAnalysis;
|
||||
namespace Serein.Extend.NewtonsoftJson
|
||||
{
|
||||
|
||||
public enum ProviderType
|
||||
{
|
||||
Default = 0,
|
||||
Web = 1,
|
||||
}
|
||||
/// <summary>
|
||||
/// 基于Newtonsoft.Json的IJsonProvider实现
|
||||
/// </summary>
|
||||
@@ -20,39 +15,23 @@ namespace Serein.Extend.NewtonsoftJson
|
||||
private JsonSerializerSettings? settings;
|
||||
|
||||
/// <summary>
|
||||
/// 基于Newtonsoft.Json的JSON门户实现
|
||||
/// 基于Newtonsoft.Json的JSON门户实现,默认首字母小写、忽略null
|
||||
/// </summary>
|
||||
public NewtonsoftJsonProvider()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 基于Newtonsoft.Json的JSON门户实现
|
||||
/// </summary>
|
||||
/// <param name="jsonType"></param>
|
||||
public NewtonsoftJsonProvider(ProviderType jsonType)
|
||||
{
|
||||
settings = jsonType switch
|
||||
{
|
||||
ProviderType.Web => new JsonSerializerSettings
|
||||
{
|
||||
ContractResolver = new CamelCasePropertyNamesContractResolver(), // 控制首字母小写
|
||||
NullValueHandling = NullValueHandling.Ignore // 可选:忽略 null
|
||||
},
|
||||
_ => new JsonSerializerSettings
|
||||
{
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
public NewtonsoftJsonProvider(JsonSerializerSettings settings)
|
||||
{
|
||||
settings = new JsonSerializerSettings
|
||||
{
|
||||
ContractResolver = new CamelCasePropertyNamesContractResolver(), // 控制首字母小写
|
||||
NullValueHandling = NullValueHandling.Ignore // 可选:忽略 null
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 使用自定义的序列化设置
|
||||
/// </summary>
|
||||
/// <param name="settings"></param>
|
||||
public NewtonsoftJsonProvider(JsonSerializerSettings settings)
|
||||
{
|
||||
this.settings = settings;
|
||||
}
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
<BaseOutputPath>..\.\.Output</BaseOutputPath>
|
||||
|
||||
<Title>为 SereinFlow 提供的 JSON 扩展</Title>
|
||||
<Version>1.0.1</Version>
|
||||
<Version>1.0.2</Version>
|
||||
<Description>通过 NewtonsoftJson 实现JSON门户扩展,用于解决 Serein.Proto.* 项目下需要 JSON 序列化与反序列化的场景</Description>
|
||||
<PackageLicenseExpression>MIT</PackageLicenseExpression>
|
||||
<PackageRequireLicenseAcceptance>True</PackageRequireLicenseAcceptance>
|
||||
|
||||
Reference in New Issue
Block a user