I am trying to learn this new system.io.pipelines, and the new webapi strategy for deserializing json...
I wrote my own JsonConverter, but I can't figure out the correct way to initialize a Utf9JsonReader from a json flat file fixture.
here is the test:
[Fact]
public void WhenGivenJsonObjectThenEntityDTOReturned() {
using(var stream = new FileStream("Fixtures/BookStoreJson.json", FileMode.Open))
{
var pipe = PipeReader.Create(stream);
ReadResult bytes;
pipe.TryRead(out bytes);
var reader = new Utf8JsonReader(bytes.Buffer);
var target = new EntityDTOConverter();
reader.Read();
var actual = target.Read(ref reader, typeof(EntityDTO), new JsonSerializerOptions());
Assert.True(actual.Props.ContainsKey("name"));
}
}
When I debug this, the bytes.buffer is set to 0 bytes, even though the BookStoreJson.json file contains the following:
{
"name": "Tattered Cover",
"store":{
"book":[
{
"category":"reference",
"author":"Nigel Rees",
"title":"Sayings of the Century",
"price":8.95
},
{
"category":"fiction",
"author":"Evelyn Waugh",
"title":"Sword of Honour",
"price":12.99
},
{
"category":"fiction",
"author":"J. R. R. Tolkien",
"title":"The Lord of the Rings",
"isbn":"0-395-19395-8",
"price":22.99
}
],
"bicycle":{
"color":"red",
"price":19.95
}
}
}