1. Alex Riofrio
  2. PowerBuilder
  3. Wednesday, 27 January 2021 00:20 AM UTC

Hello,
I'm following the tutorial: https://docs.appeon.com/dwconverter2019r3/CRUD_Operations_with_.NET_DataStore/index.html

But when I call the Create method from PowerBuilder 2019 R3 I get the following error message: "JSON value could not be converted to System.Datetime"

I have tested this same function from the "Web API Tester" and it works without problems.

I am working with:
PB and SnapDevelop 2019 R3 Build 2670.
SQL Server 2017.

 

In PB I use the follow sintax to set the request headers

// Set the Request Headers to tell the Web API you will send JSON data
inv_RestClient.SetRequestHeader ("Content-Type", "application/json;charset=UTF-8")

// Set the Request Headers to accept GZIP compression
inv_RestClient.SetRequestHeader("Accept-Encoding", "gzip")

 

The client and Web API side are completely new.

Thanks in advance for any help,

Alex

Attachments (1)
Alex Riofrio Accepted Answer Pending Moderation
  1. Wednesday, 27 January 2021 14:10 PM UTC
  2. PowerBuilder
  3. # 1

Hello Logan :)
Thank you very much for your answer.
Ok, I'll open a ticket to report this issue.
For now, Couldn't I use .NET Core 3.1 in Web API projects with .NET DataStore and with a PB Client DataWindows (with a DateTime data type)?

Alex

Comment
  1. Logan Liu @Appeon
  2. Thursday, 28 January 2021 18:08 PM UTC
You can use .NET Core 3.1 in Web API projects with .NET DataStore and with a PB Client DataWindows (with a DateTime data type).



Except perform custom parsing or formatting with the System.Text.Json library

https://docs.microsoft.com/en-us/dotnet/standard/datetime/system-text-json-support#custom-support-for--and-

, there are also two simple solutions:



1) Only modify your ASPNET Core 3.1 Web API project to switch from using the new System.Text.Json package back to using Newtonsoft.Json.

Install-Package Microsoft.AspNetCore.Mvc.NewtonsoftJson.

Then add the following code in Startup.ConfigureServices():

services.AddControllers().AddNewtonsoftJson();

Refer to:

https://docs.microsoft.com/en-us/aspnet/core/migration/22-to-30?view=aspnetcore-3.0&tabs=visual-studio#use-newtonsoftjson-in-an-aspnet-core-30-mvc-project



2) Send DataWindow JSON from your PB application to the Server-side instead of Plain JSON. And use an IDataStore type parameter in your controller to receive data.
  1. Helpful
  1. Alex Riofrio
  2. Friday, 29 January 2021 16:10 PM UTC
Thank you very much Logan;

I solved it with the first procedure, adding the Microsoft.AspNetCore.Mvc.NewtonsoftJson package (version 3.1.11).

:)
  1. Helpful
  1. Miguel Leeuwe
  2. Friday, 29 January 2021 16:18 PM UTC
Thanks for sharing Alex, please mark as "resolved".
  1. Helpful
There are no comments made yet.
Logan Liu @Appeon Accepted Answer Pending Moderation
  1. Wednesday, 27 January 2021 10:40 AM UTC
  2. PowerBuilder
  3. # 2

Hi Alex,

Glad to see you again! Thank you for reporting this issue.  

1) If you are creating a .NET Core 2.1 Web API project, this issue will not exist. But you can see it in a .NET Core 3.1 Web API project. The System.Text.Json library is built-in as part of the shared framework for .NET Core 3.0 and later versions.

The System.Text.Json library parses and writes DateTime and DateTimeOffset values according to the ISO 8601:-2019 extended profile. The JsonSerializerUtf8JsonReaderUtf8JsonWriter, and JsonElement types parse and write DateTime and DateTimeOffset text representations according to the extended profile of the ISO 8601-1:2019 format; for example, 2019-07-26T16:59:57-05:00.

Refer to https://docs.microsoft.com/en-us/dotnet/standard/datetime/system-text-json-support

2) The format of a DataTime generated by PowerBuilder is still using PB Datetime standard format which is different from ISO 8601-1:2019 format. Please submit a PB ticket to track this issue.  And we will add more details to this document to let more users notice this change.

3)  To work around this, if you want the serializer to perform custom parsing or formatting, you can implement custom converters

Regards,

Logan

Comment
There are no comments made yet.
  • Page :
  • 1


There are no replies made for this question yet.
However, you are not allowed to reply to this question.