I´m trying to write Unit Tests for an extension method of stream which internally uses
return await JsonSerializer
.DeserializeAsync(@this, type, options ?? JsonFlatOptions)
.ConfigureAwait(false);
where @this would be my stream
I tried
´´´
var dog = new Dog() { Name = "Merlina" };
byte[] jsonUtf8Bytes = JsonSerializer.SerializeToUtf8Bytes(dog);
var json = JsonSerializer.Serialize(dog);
var stream = new MemoryStream();
stream.Write(jsonUtf8Bytes, 0, jsonUtf8Bytes.Length);
´´´
But when trying to deserialize it I get the following error message:
Message: System.Text.Json.JsonException : The input does not contain any JSON tokens. Expected the input to start with a valid JSON token, when isFinalBlock is true. Path: $ | LineNumber: 0 | BytePositionInLine: 0. ----> System.Text.Json.JsonReaderException : The input does not contain any JSON tokens. Expected the input to start with a valid JSON token, when isFinalBlock is true. LineNumber: 0 | BytePositionInLine: 0.
I´m trying to get an appropriate stream to use
The documentations says that this method Deserializes a JSON stream of UTF8 bytes into a dynamic object.