diff --git a/NuGet.Config b/NuGet.Config index d0582142..f39adfbb 100644 --- a/NuGet.Config +++ b/NuGet.Config @@ -2,6 +2,6 @@ - + \ No newline at end of file diff --git a/common.props b/common.props index 6f48fba8..00914e05 100644 --- a/common.props +++ b/common.props @@ -9,7 +9,7 @@ https://raw.githubusercontent.com/liuhll/silky/main/LICENSE - 3.7.11 + 3.7.12 https://raw.githubusercontent.com/liuhll/silky/main/docs/.vuepress/public/assets/logo/logo.png diff --git a/framework/src/Silky.Core/Serialization/DefaultSerializer.cs b/framework/src/Silky.Core/Serialization/DefaultSerializer.cs index 53f53c4c..8aba5e90 100644 --- a/framework/src/Silky.Core/Serialization/DefaultSerializer.cs +++ b/framework/src/Silky.Core/Serialization/DefaultSerializer.cs @@ -16,6 +16,7 @@ public string Serialize(object instance, bool camelCase = true, bool indented = if (camelCase) { settings.ContractResolver = new CamelCasePropertyNamesContractResolver(); + settings.Converters.Add(new JObjectConverter()); } else { diff --git a/framework/src/Silky.Core/Serialization/JObjectConverter.cs b/framework/src/Silky.Core/Serialization/JObjectConverter.cs new file mode 100644 index 00000000..21c1381c --- /dev/null +++ b/framework/src/Silky.Core/Serialization/JObjectConverter.cs @@ -0,0 +1,19 @@ +using System; +using System.Dynamic; +using Newtonsoft.Json; +using Newtonsoft.Json.Linq; + +namespace Silky.Core.Serialization; + +public class JObjectConverter : JsonConverter +{ + public override bool CanRead => false; + + public override bool CanConvert(Type objectType) => objectType == typeof(JObject); + + public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) + => throw new NotImplementedException(); + + public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) + => JToken.FromObject((value as JObject).ToObject(), serializer).WriteTo(writer); +} \ No newline at end of file diff --git a/framework/test/ITestApplication/Test/ITestAppService.cs b/framework/test/ITestApplication/Test/ITestAppService.cs index 1be90ca9..afa4e44f 100644 --- a/framework/test/ITestApplication/Test/ITestAppService.cs +++ b/framework/test/ITestApplication/Test/ITestAppService.cs @@ -49,6 +49,10 @@ public interface ITestAppService [HttpDelete] Task DeleteAsync(long id); + [HttpGet] + Task> TestDict1(); + + [HttpGet] Task> Search1([FromQuery] string name, [FromQuery] string address, [FromQuery] IList ids, diff --git a/framework/test/TestApplication/AppService/TestAppService.cs b/framework/test/TestApplication/AppService/TestAppService.cs index e30a627e..b82fb451 100644 --- a/framework/test/TestApplication/AppService/TestAppService.cs +++ b/framework/test/TestApplication/AppService/TestAppService.cs @@ -92,7 +92,7 @@ public async Task DeleteAsync(long id) // await _anotherAppService.DeleteOne(input.Name); // await _anotherAppService.DeleteTwo(input.Address); // // throw new BusinessException("test exception"); - // + // var entity = await _testRepository.FindOrDefaultAsync(id); if (entity == null) { @@ -104,6 +104,15 @@ public async Task DeleteAsync(long id) return "删除数据成功"; } + public async Task> TestDict1() + { + return new Dictionary() + { + { "Id", "1" }, + { "Name", "Name" } + }; + } + public async Task> Search1(string name, string address, IList ids, int pageIndex = 1, int pageSize = 10) {