Hi,
i have a problem if i add localizable items to a schema.
If i load the data via Postman with X-Languages and X-Flatten Header everything works as expected, but if i load the data via the ClientLibrary i got an exception:
An unhandled exception occurred while processing the request.
JsonSerializationException: Property must have a invariant language property.
Squidex.ClientLibrary.InvariantConverter.ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
My Code:
public async Task<List<Page>> GetPagesAsync()
{
var context = QueryContext.Default.WithLanguages("en").Flatten();
var pages = await this.pagesClient.GetAsync(context: context);
return pages.Items;
}
public sealed class PostData
{
[JsonConverter(typeof(InvariantConverter))]
public Header[] Header { get; set; }
[JsonConverter(typeof(InvariantConverter))]
public string Text { get; set; }
}
public sealed class Header
{
[JsonConverter(typeof(InvariantConverter))]
public string Name{ get; set; }
[JsonConverter(typeof(InvariantConverter))]
public string Text { get; set; }
...
}
MY API:
var query = new ODataQuery { Skip = page * pageSize, Top = pageSize };
var context = QueryContext.Default.WithLanguages("de").Flatten();
`var posts = await postsClient.GetAsync(query, context);`
JsonSerializationException: Cannot deserialize the current JSON array (e.g. [1,2,3]) into type ‘System.Collections.Generic.Dictionary`2[System.String,Models.Header[]]’ because the type requires a JSON object (e.g. {“name”:“value”}) to deserialize correctly.
To fix this error either change the JSON to a JSON object (e.g. {“name”:“value”}) or change the deserialized type to an array or a type that implements a collection interface (e.g. ICollection, IList) like List that can be deserialized from a JSON array. JsonArrayAttribute can also be added to the type to force it to deserialize from a JSON array
Unfortunately, that’s still not possible, I had already tried that. Is there possibly still another error? I have created an array of languages in the schema
Dictionary<string, Header> Header Does not work either
i can only write 3 replays. to the last comment: InvariantConverter
hi, I had meanwhile removed that. if I have it in the message comes:
JsonSerializationException: Property must have a invariant language property.
public sealed class PostsVM
{
public List<Post> Posts { get; set; }
public long Total { get; set; }
public long Page { get; set; }
public long PageSize { get; set; }
}
public sealed class Post : SquidexEntityBase<PostData>
{
}
public sealed class PostData
{
public Dictionary<string, Header> Header { get; set; }
[JsonConverter(typeof(InvariantConverter))]
public string Text { get; set; }
}
public sealed class Header
{
[JsonConverter(typeof(InvariantConverter))]
public string Name{ get; set; }
[JsonConverter(typeof(InvariantConverter))]
public string Text { get; set; }
[JsonConverter(typeof(InvariantConverter))]
public string Previewtext { get; set; }
}
Abfrage:
public async Task<(long Total, List<Post> Posts)> GetPostsAsync(int page = 0, int pageSize = 3)
{
var query = new ODataQuery { Skip = page * pageSize, Top = pageSize };
var context = QueryContext.Default.WithLanguages("de").Flatten();
var posts = await postsClient.GetAsync(query, context);
return (posts.Total, posts.Items);
}
public sealed class Post : SquidexEntityBase<PostData>
{
}
public sealed class PostData
{
public Dictionary<string, Header[]> Header { get; set; }
[JsonConverter(typeof(InvariantConverter))]
public string Text { get; set; }
}
public sealed class Header
{
public string Name{ get; set; }
public string Text { get; set; }
public string Previewtext { get; set; }
}