You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am strugling with the serialization of IPagedList using JSON.NET.
Also asked a question on StackOverflow(1) as it is maybe not an issue with this library per se, but that I have to implement a custom serializer/deserializer to make it work.
I have the following use case, I want to serialize/deserialize my IPagedList of T using JSON.net (Newtonsoft.Json). This seems not to be working. It does not serialize everything, only the items (or with my own ContractResolver, the object with empty properties).
A test case:
var list = new List(Enumerable.Range(1, 1000));
var paged = list.AsQueryable().ToPagedList(3, 10);
var json = JsonConvert.SerializeObject(paged); (output: [21,22,23,24,25,26,27,28,29,30])
var obj = JsonConvert.DeserializeObject<PagedList>(json);
Questions:
Why do only the items get serialized? (cannot serialize back to the PagedList because of that, I guess)
Is there a 'known' solution to serialize the pagedlist?
Found (2) which correctly makes me serialize the PagedList but that cannot convert back to the IPagedList, are there implementations for serialization for this library?
This is not a bug. JSON support only simple arrays and cannot serialize complex object which inherite from array type. You should resolve it manual. For ex. serialize separately PagedListMetaData object and elements.
I am strugling with the serialization of IPagedList using JSON.NET.
Also asked a question on StackOverflow(1) as it is maybe not an issue with this library per se, but that I have to implement a custom serializer/deserializer to make it work.
I have the following use case, I want to serialize/deserialize my IPagedList of T using JSON.net (Newtonsoft.Json). This seems not to be working. It does not serialize everything, only the items (or with my own ContractResolver, the object with empty properties).
A test case:
var list = new List(Enumerable.Range(1, 1000));
var paged = list.AsQueryable().ToPagedList(3, 10);
var json = JsonConvert.SerializeObject(paged); (output: [21,22,23,24,25,26,27,28,29,30])
var obj = JsonConvert.DeserializeObject<PagedList>(json);
Questions:
Found (2) which correctly makes me serialize the PagedList but that cannot convert back to the IPagedList, are there implementations for serialization for this library?
The text was updated successfully, but these errors were encountered: