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

Serialize/Deserialize to/from Stream #232

Closed thecodrr closed 3 years ago

thecodrr commented 3 years ago

I am trying to use it in an aspnetcore app. I want to replace Utf8Json with this library.

Utf8Json can read/write to/from Stream:

// Deserialize
await JsonSerializer.NonGeneric.DeserializeAsync(context.ModelType, request.Body, resolver);

// Serialize
JsonSerializer.NonGeneric.SerializeAsync(context.ObjectType, context.HttpContext.Response.Body, context.Object, resolver);

*.Body being a Stream.

Is this possible to do? I noticed NetJSON has the ability to use TextReader/TextWriter, can that be used?

NetJSON.Deserialize<T>(TextReader reader) only has a generic interface. Can it have something like: NetJSON.Deserialize(Type type, TextReader reader)?

rpgmaker commented 3 years ago

The text Writer and reader are actually reading the full stream into a string/string builder. So it is not currently reading bytes in chunk.

So you are better off reading the full stream and using the deserialize method with type and string parameter.

I do plan on revisiting the implementation of text reader and writer later.

thecodrr commented 3 years ago

Yes, that's what I ended up doing. Would be cool to do it in chunks.

rpgmaker commented 3 years ago

I will revisit in the future for sure. If you don't mind . Can you close the ticket and create a separate ticket for a feature request if you want and I can look at it when I free up time.

thecodrr commented 3 years ago

Awesome.