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

Serialize/deserialize IPagedList<T> using JSON.NET #57

Closed
ronaldme opened this issue Oct 18, 2016 · 2 comments
Closed

Serialize/deserialize IPagedList<T> using JSON.NET #57

ronaldme opened this issue Oct 18, 2016 · 2 comments

Comments

@ronaldme
Copy link

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:

  1. Why do only the items get serialized? (cannot serialize back to the PagedList because of that, I guess)
  2. 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?

  1. http://stackoverflow.com/questions/40101674/serialize-deserialize-ipagedlistt-using-json-net?noredirect=1#comment67475706_40101674
  2. https://stackoverflow.com/questions/12129774/serialize-custom-properties-on-a-class-that-implements-ienumerable
@emouawad
Copy link

+1 I think this is important.
Would be essential having this done.
Thank you.

@ernado-x
Copy link
Member

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.

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

No branches or pull requests

3 participants