public void ReadBytesFromEmptyString() { var bytes = new HasBytes { Bytes = new byte[0] }; var json = JsonConvert.SerializeObject(bytes); TextReader textReader = new StringReader(json); JsonReader jsonReader = new JsonTextReader(textReader); var jToken = JToken.ReadFrom(jsonReader); jsonReader = new JTokenReader(jToken); var result2 = (HasBytes)JsonSerializer.Create(null) .Deserialize(jsonReader, typeof(HasBytes)); CollectionAssert.AreEquivalent(new byte[0], result2.Bytes); }
public void ReadBytesFromString() { var bytes = new HasBytes { Bytes = new byte[] { 1, 2, 3, 4 } }; var json = JsonConvert.SerializeObject(bytes); TextReader textReader = new StringReader(json); JsonReader jsonReader = new JsonTextReader(textReader); var jToken = JToken.ReadFrom(jsonReader); jsonReader = new JTokenReader(jToken); var result2 = (HasBytes)JsonSerializer.Create(null) .Deserialize(jsonReader, typeof(HasBytes)); Assert.AreEqual(new byte[] { 1, 2, 3, 4 }, result2.Bytes); }
public void ReadBytesFromString() { var bytes = new HasBytes { Bytes = new byte[] { 1, 2, 3, 4 } }; var json = JsonConvert.SerializeObject(bytes); TextReader textReader = new StringReader(json); JsonReader jsonReader = new JsonTextReader(textReader); var jToken = JToken.ReadFrom(jsonReader); jsonReader = new JTokenReader(jToken); var result2 = (HasBytes)JsonSerializer.Create(null) .Deserialize(jsonReader, typeof(HasBytes)); Assert.Equal(new byte[] { 1, 2, 3, 4 }, result2.Bytes); }