Unexpected token parsing date. Expected String, got StartObject

I have…

  • [ X] Read the following guideline: Troubleshooting and Support - Squidex. I understand that my support request might get deleted if I do not follow the guideline.
  • Used code blocks with ``` to format my code examples like JSON or logs properly.

I’m submitting a…

  • Regression (a behavior that stopped working in a new release)
  • Bug report
  • Performance issue
  • Documentation issue or request

Current behavior

(I checked Bug report but 99% I’m newbie and I miss something…)
I have a simple schema with a datetime field that I mapped with

    [Newton.JsonProperty()]
    public DateTime PublishDate { get; set; }

when I try to retrieve with the .net sdk

var youtubeVideoClient =  client.Contents<YoutubeVideo, YoutubeVideoData>("youtubevideo");
var video = await youtubeVideoClient.GetAsync("fd8ae577-a6c9-4ad2-824a-ed49bd24fcfb");

I receive an error
Unhandled exception. Newtonsoft.Json.JsonSerializationException: Unexpected token parsing date. Expected String, got StartObject. Path ‘data.PublishDate’, line 1, position 357.
at Newtonsoft.Json.Converters.IsoDateTimeConverter.ReadJson(JsonReader reader, Type objectType, Object existingValue, JsonSerializer serializer)

The field is correctly populated (checked with Preview and Postman)
“PublishDate”: {
“en”: “2023-02-20T00:00:00Z”,
“de”: “2023-11-17T00:00:00Z”,
“it”: “2023-02-20T00:00:00Z”
}

Expected behavior

No parsing error

Minimal reproduction of the problem

Environment

App Name:

  • Self hosted with docker
  • Self hosted with IIS
  • Self hosted with other version
  • [ X] Cloud version

Version: [VERSION]

Browser:

  • [X ] Chrome (desktop)
  • Chrome (Android)
  • Chrome (iOS)
  • Firefox
  • Safari (desktop)
  • Safari (iOS)
  • IE
  • Edge

Others:
“Newtonsoft.Json” Version=“13.0.3”
“Squidex.ClientLibrary” Version=“19.1.0”
Thank you

Hi,

have you read this: .NET - Squidex?

Hallo Sebastian,
thanks for your answer (above all because Sunday).

Yes… I read (I’m not the guy who doesn’t search before to ask help)

I switched the NetwonSoft attribute between localizable and not localizable properties

Sorry

S.

For localized fields you have to use a dictionary

public Dictionary<string, DateTime> PublishDate { get; set; }

For non-localized fields you CAN use the invariant converter

[JsonConverter(typeof(InvariantConverter))]
public DateTime PublishDate { get; set; }

Thanks Sebastian.

last question: what is the best method to learn the .NET library and all the features offered?
Is there a documentation/sample/white paper that explains the various method offered by the client, apart installation and the GetAsync() method?

Eg. I discovered a IsIgnoreFallback property of the QueryContext class.
But where and how is QueryContext used?

Thanks

The .NET library is just generated code over the API. I would have a look the the API first: API Docs

Everything you do via UI, can also be done via the API and therefore via the library.

The QueryContext is used to transport some headers to the backend, e.g. Localization - Squidex

It is used for edge cases. If you are just learning, I would ignore that.

1 Like