Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dates are being deserialized with kind Local (with potential fix) #75

Open
crochik opened this issue Feb 11, 2025 · 3 comments
Open

Dates are being deserialized with kind Local (with potential fix) #75

crochik opened this issue Feb 11, 2025 · 3 comments

Comments

@crochik
Copy link

crochik commented Feb 11, 2025

Noticed yesterday that dates were coming back with kind Local.

It is my understanding dates from salesforce are all provided as UTC but because of their format (e.g. 2017-05-30T21:10:25.000+0000) the JsonConvert.DeserializeObject by default will attempt some kind of conversion to Local.

It seems like a simple fix (that worked for me):

In JsonClient.cs wherever the JsonConvert.DeserializeObject<T>(...) is being used to deserialize the response, replace with:

JsonConvert.DeserializeObject<T>(..., new JsonSerializerSettings { DateTimeZoneHandling = DateTimeZoneHandling.Utc })
@crochik crochik changed the title Dates are being deserialized with kind Local. Dates are being deserialized with kind Local (with potential fix) Feb 11, 2025
@anthonyreilly
Copy link
Owner

Are you using DateTime or DateTimeOffset in your model objects? I did a quick test and DateTimeOffset is parsing correctly. I'll see if I can add that change without breaking DateTimeOffset parsing.

@crochik
Copy link
Author

crochik commented Feb 11, 2025

hi @anthonyreilly. I actually don't define models and use the ExpandoObject so the JsonConvert will create DateTime properties for Date looking properties.

@anthonyreilly
Copy link
Owner

hi @anthonyreilly. I actually don't define models and use the ExpandoObject so the JsonConvert will create DateTime properties for Date looking properties.

Thanks, I'm writing some tests now, so I'll include an ExpandoObject case as well

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants