Reputation: 613
Is there any way to have Json.net serialize an object directly to a NetworkStream?
In other words, have Json.net send the serialized result to the network as it serializes the object (in a streaming fashion).
I would like to avoid having to serialize the object to memory and then send it via the NetworkStream.
Any thoughts?
Regards
Upvotes: 1
Views: 778
Reputation: 54714
You can create a TextWriter
on top of a NetworkStream
, and serialize to the TextWriter
; or you can create a JsonTextWriter
on top of a TextWriter
and serialize to that.
You don't need to serialize to, say, a temporary string or byte array first.
Upvotes: 1