rpgmaker / NetJSON

Faster than Any Binary? Benchmark: http://theburningmonk.com/2014/08/json-serializers-benchmarks-updated-2/
MIT License
225 stars 29 forks source link

Infinite loop for string skipping... #58

Closed StefanBelo closed 9 years ago

StefanBelo commented 9 years ago

Problem to deserialize this JSON:

{"jsonrpc":"2.0","result":{"currencyCode":"EUR","firstName":"Stefan","lastName":"Surname","localeCode":"en","region":"GBR","timezone":"CET","discountRate":2.0,"pointsBalance":1181,"countryCode":"SK"},"id":1}
rpgmaker commented 9 years ago

Can you please verify that it works?

Thanks,

StefanBelo commented 9 years ago

Infinite loop on this JSON:

{"jsonrpc":"2.0","result":[{"eventType":{"id":"1","name":"Soccer"},"marketCount":324}],"id":1}

But that is because my model declares eventType.Id as int, not as string.

I am testing the rest of api. There is a problem with serialization of enums, for now I use Newtonsoft serialization.

rpgmaker commented 9 years ago

That is a known issue in regards to type mismatch. Here an issue I created for a it about some weeks ago: https://github.com/rpgmaker/NetJSON/issues/54

Does newtonsoft simple auto convert it for you when you have a mismatch?

In regards to enumeration, I am sure it is same issue too where newtonsoft convert between int and string to the correct enum whereas I require to be told whether in the pipeline to use enum as string or int. On Jun 8, 2015 5:21 AM, "Stefan Belopotocan" notifications@github.com wrote:

Infinite loop on this JSON:

{"jsonrpc":"2.0","result":[{"eventType":{"id":"1","name":"Soccer"},"marketCount":324}],"id":1}

But that is because my model declares eventType.Id as int, not as string.

I am testing the rest of api. There is a problem with serialization of enums, for now I use Newtonsoft serialization.

— Reply to this email directly or view it on GitHub https://github.com/rpgmaker/NetJSON/issues/58#issuecomment-109924540.

StefanBelo commented 9 years ago

Yes, when newtonsoft deserializes to model it expects what model declares and so makes conversion from json string, so even if json says "id":"1" that id is string it takes string value and converts it to required model data representation.

I have got problem with serialization of enums, and I set NetJSON.UseEnumString to true. I will prepare some test data and open another issue for this one.

When testing other JSON libraries for de/serialization I wanted to get as the best performance as possibly, so I tested on models different ways of representing collection data: array, list, IEnumerable ...

I hope you understand what I want to say, JSON deserializing either using model collection type and adds element types, or uses internal collection for adding elements and when data parsing is done copies/converts to model collection. In newtonsoft I tried to use IEnumerable on my models hoping that library returns internal collection objects, but I have got best performance with List.

How is it in your library? It is hard to debug it but I can see you have got GenerateCreateListFor function, so you maybe also reuse model collection directly.

rpgmaker commented 9 years ago

At the moment, I don't have full support for deserialization/serialization using IEnumerable for IList object yet, but I do have full support for using IList types such as List[T], Array, ArrayList, and e.t.c. I do have full support using any dictionary object such as IEnumerable[K,V], IDictionary, IDictionary[K,V], and any dictionaries such as HashSet, ConcurrentDictionary, ExpandoObject, Dictionary, or anything that implement IDictionary or IEnumerable[K,V].

It also support complex serialization/deserialization to Dictionary[String, Object] which most library don't fully support when it comes to deserialization.

I have a pull request that suggested fixing the issue with using IList/LIst[T] with IEnumerable[T] that I have not fully implemented yet, but is in my list of todo.

Thanks,

rpgmaker commented 9 years ago

As for the type mismatch issue, my plans is to implement a solution that will throw an exception. But I will also go ahead an add an option to allow mismatch where it will either try to do the type conversation automatically if possible. But the option will be for people who are ok with performance degrade when dealing with unknowns.

Thanks,

StefanBelo commented 9 years ago

Thanks for your work. In my case the performance gain is about 50% comparing to Newtonsoft library.