public override Maybe <T> Read(ref System.Text.Json.Utf8JsonReader reader, Type typeToConvert, System.Text.Json.JsonSerializerOptions options) { switch (reader.TokenType) { case System.Text.Json.JsonTokenType.Null: return(Maybe <T> .None); default: var deserialized = System.Text.Json.JsonSerializer.Deserialize <T>(ref reader, options); return(Maybe <T> .From(deserialized)); } }
/// <summary> /// Returns true when deserialization succeeds. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="reader"></param> /// <param name="options"></param> /// <param name="result"></param> /// <returns></returns> public static bool TryDeserialize <T>(ref System.Text.Json.Utf8JsonReader reader, System.Text.Json.JsonSerializerOptions options, [System.Diagnostics.CodeAnalysis.NotNullWhen(true)] out T?result) { try { result = System.Text.Json.JsonSerializer.Deserialize <T>(ref reader, options); return(result != null); } catch (Exception) { result = default; return(false); } }
public override string Read(ref System.Text.Json.Utf8JsonReader reader, Type typeToConvert, System.Text.Json.JsonSerializerOptions options) { var s = reader.GetString(); if (s != null) { return(string.Intern(s)); } else { return(null); } }
/// <summary> /// Returns true when deserialization succeeds. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="reader"></param> /// <param name="options"></param> /// <param name="result"></param> /// <returns></returns> public static bool TryDeserialize <T>(ref System.Text.Json.Utf8JsonReader reader, System.Text.Json.JsonSerializerOptions options, out T result) { try { result = System.Text.Json.JsonSerializer.Deserialize <T>(ref reader, options); return(result != null); } catch (Exception) { result = default; return(false); } }
public override EmailAddress Read(ref System.Text.Json.Utf8JsonReader reader, Type typeToConvert, System.Text.Json.JsonSerializerOptions options) { if (reader.TokenType == System.Text.Json.JsonTokenType.Null) { return(null); } else if (reader.TokenType == System.Text.Json.JsonTokenType.String && EmailAddress.TryParse(reader.GetString(), out EmailAddress address)) { return(address); } else { throw new System.Text.Json.JsonException($"Current value is not a valid {nameof(EmailAddress)}"); } }
public override PhoneNumber Read(ref System.Text.Json.Utf8JsonReader reader, Type typeToConvert, System.Text.Json.JsonSerializerOptions options) { if (reader.TokenType == System.Text.Json.JsonTokenType.Null) { return(null); } else if (reader.TokenType == System.Text.Json.JsonTokenType.String && PhoneNumber.TryParse(reader.GetString(), out PhoneNumber phoneNumber)) { return(phoneNumber); } else { throw new System.Text.Json.JsonException($"Current value is not a valid {nameof(PhoneNumber)}"); } }
public override System.TimeSpan Read(ref System.Text.Json.Utf8JsonReader Utf8JsonReader, System.Type Type, System.Text.Json.JsonSerializerOptions JsonSerializerOptions) { System.String Value = Utf8JsonReader.GetString(); if (System.String.IsNullOrWhiteSpace(Value)) { return(System.TimeSpan.Zero); } System.TimeSpan Result; if (!(System.TimeSpan.TryParseExact(Value, Format, null, out Result))) { throw new System.FormatException("The provided TimeSpan is invalid."); } return(Result); }
public static ProblemDetails ShouldBeProblemDetails(this HttpResponseMessage response, HttpStatusCode statusCode) { response.StatusCode.Should().Be(statusCode); response.Content.Headers.ContentType.MediaType.Should().Be("application/problem+json"); var str = response.Content.ReadAsStringAsync().Result; var converter = new ProblemDetailsJsonConverter(); var reader = new System.Text.Json.Utf8JsonReader(System.Text.Encoding.UTF8.GetBytes(str)); var problemDetails = converter.Read(ref reader, typeof(ProblemDetails), new JsonOptions().JsonSerializerOptions); problemDetails.Should().NotBeNull(); problemDetails.Status.Should().Be((int)statusCode); problemDetails.Title.Should().NotBeNull(); problemDetails.Type.Should().NotBeNull(); problemDetails.Detail.Should().NotBeNull(); problemDetails.Instance.Should().Be(response.RequestMessage.RequestUri.AbsolutePath); return(problemDetails); }
public static bool TryParseValue(ref System.Text.Json.Utf8JsonReader reader, out System.Text.Json.JsonDocument document) { throw null; }
public static System.Text.Json.JsonDocument ParseValue(ref System.Text.Json.Utf8JsonReader reader) { throw null; }
public static TValue Deserialize <TValue>(ref System.Text.Json.Utf8JsonReader reader, System.Text.Json.JsonSerializerOptions options = null) { throw null; }
public static object Deserialize(ref System.Text.Json.Utf8JsonReader reader, System.Type returnType, System.Text.Json.JsonSerializerOptions options = null) { throw null; }
public override object Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) { throw null; }
public override StringId Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) { return(new StringId(reader.GetString())); }
public override Azure.Core.Spatial.Geometry Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) { throw null; }
public static bool TryParseValue(ref System.Text.Json.Utf8JsonReader reader, [System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] out System.Text.Json.JsonDocument?document) { throw null; }
public sealed override BinaryData?Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) { throw null; }
object IClientConverter.Read(ref System.Text.Json.Utf8JsonReader jreader, object item, System.Text.Json.JsonSerializerOptions options) { throw new NotSupportedException(); }
public override Microsoft.AspNetCore.Components.ElementReference Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) { throw null; }