Web Connection
JsonSerializer
Gravatar is a globally recognized avatar based on your email address. JsonSerializer
  Zul
  All
  Aug 19, 2021 @ 03:38pm

I am using web connection 7.20 to consume RestAPI. The api sends json response where one field called upset_at always has a value in this format: 2021-05-16T04:46:11.522669Z

My question: Is there any way upon deserialization I could retain the value as is. I know it cannot be converted to VFP datetime as is, but how if I could get it as a string?

Gravatar is a globally recognized avatar based on your email address. re: JsonSerializer
  Rick Strahl
  Zul
  Aug 19, 2021 @ 06:24pm

Not sure what you're asking. wwJsonSerializer will deserialize JSON dates into FoxPro. There's no support for returning the raw value as a string, since the serializer will always deserialize the date.

+++ Rick ---

Gravatar is a globally recognized avatar based on your email address. re: JsonSerializer
  Zul
  Rick Strahl
  Aug 19, 2021 @ 09:38pm

Some property on the serializer where one could provide a list of json attributes whose values should not be cast rather left as string.

Thanks

Gravatar is a globally recognized avatar based on your email address. re: JsonSerializer
  Rick Strahl
  Zul
  Aug 19, 2021 @ 09:51pm

This is not supported.

+++ Rick ---

Gravatar is a globally recognized avatar based on your email address. re: JsonSerializer
  Rick Strahl
  Zul
  Aug 19, 2021 @ 09:53pm

Serialization customization for specific types is not supported.

But if you are concerned about the date that you are referencing that is automatically deserialized into a FoxPro date. That date you show is a standard JSON date and the serializer understands that.

+++ Rick ---

Gravatar is a globally recognized avatar based on your email address. re: JsonSerializer
  Carl Chambers
  Zul
  Aug 19, 2021 @ 10:28pm

Hi Zul,

If the name of the property is consistent, you could use string manipulation to wrap the JSON datetime with quotes before you deserialize the JSON. It should then treat the datetime as a string.

I had to do something like this with JSON responses that have "id" fields that are 64-bit integers.
Eventually, they may become too large for FoxPro to handle as integers so I wrap them with quotes before deserializing and handle them as strings.

Carl

Gravatar is a globally recognized avatar based on your email address. re: JsonSerializer
  Zul
  Carl Chambers
  Aug 19, 2021 @ 11:24pm

Thanks Carl. I will try your suggestion.

I am not trying to convert that datetime with timestamp into VFP date time. I simply want to retain that exact value as is and pass it to Postgres.

I am using cursor adapter and mapping the upsert_at column as C(30) to Postgres date time with timestamp column and this retains the exact value as is in the Json response.

Thanks Rick.

Gravatar is a globally recognized avatar based on your email address. re: JsonSerializer
  Rick Strahl
  Zul
  Aug 20, 2021 @ 09:34am

But why? Does the Postgres driver not support real date values? You should be able to upsert a FoxPro date into a Postgres date and vice versa.

If you don't want a date, don't use a date...

+++ Rick ---

Gravatar is a globally recognized avatar based on your email address. re: JsonSerializer
  Zul
  Rick Strahl
  Aug 23, 2021 @ 05:27am

Thanks Rick. I got my problem solved.

© 1996-2024