Closed diennttlu closed 2 years ago
I am creating an Api for Telegram bot to call WebhookController:
Data form body: { "date": 1636083705, }
The "date" property has a unixtimestamp data type. When sending request it cannot convert to DateTime data type. I've added services.AddControllers().AddNewtonsoftJson(); to replace the . I tried it on a simple .net-core web app and it worked fine. On Abp Framework it throws an exception "The JSON value could not be counverted to System.DateTime".
Возможно кому-либо поможет, столкнулся с этой же проблемой, подружить abp и telegram бота удалось так: (Maybe i can help someone, get this trouble. My decision: )
Configure<AbpSystemTextJsonSerializerOptions>(options =>
{
//AbpHybridJsonInputFormatter.SystemTextJsonInputFormatter не может обработать атрибуты модели Telegram.Bot.Types.Update, используем NewtonsoftJsonInputFormatter:
options.UnsupportedTypes.Add(typeof(Update));
});
Configure<MvcNewtonsoftJsonOptions>(options =>
{
//Используем дефолтную Newtonsoft реализацию вместо AbpMvcJsonContractResolver:
options.SerializerSettings.ContractResolver = new DefaultContractResolver();
});
If using .NET6 JToken should be changed to JsonNode https://zhuanlan.zhihu.com/p/388545891
When I am trying to deserealize data from body json can't convert DateTime
I've added services.AddControllers().AddNewtonsoftJson(); to Startup.cs and it doesn't change anything
Abp Framework v4.4.3