public void ShouldWriteNull() { using (var writer = new SystemJsonValueWriter()) { JToken.Parse("null").WriteTo(writer); Assert.Null(writer.JsonValue); } }
public void ShouldWriteJsonAsIs(string jsonString) { var jToken = JToken.Parse(jsonString); using(var writer = new SystemJsonValueWriter()) { jToken.WriteTo(writer); Assert.Equal(jsonString, writer.JsonValue.ToString()); } }
private static JsonValue ConvertToJsonInternal(object source, JsonSerializer serializer, bool throwOnError) { using (var writer = new SystemJsonValueWriter()) try { serializer.Serialize(writer, source); return writer.JsonValue; } catch (JsonSerializationException e) { return LogAndThrowParseExceptionIfNeeded<JsonValue>( throwOnError, e, "Error converting object of type {0} to JSON", source.GetType().FullName); } }