public override ErrorProblemDetails <T> Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
        {
            var problemDetails = new ErrorProblemDetails <T>();

            if (reader.TokenType != JsonTokenType.StartObject)
            {
                throw new JsonException(UnexpectedJsonEnd);
            }

            while (reader.Read() && reader.TokenType != JsonTokenType.EndObject)
            {
                if (reader.ValueTextEquals(ErrorDetails.EncodedUtf8Bytes))
                {
                    problemDetails.ErrorDetails = JsonSerializer.Deserialize <T>(ref reader, options);
                }
                else
                {
                    ReadValue(ref reader, problemDetails, options);
                }
            }

            if (reader.TokenType != JsonTokenType.EndObject)
            {
                throw new JsonException(UnexpectedJsonEnd);
            }

            return(problemDetails);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Creates a new <see cref="ErrorDetailsObjectResult"/> instance.
        /// </summary>
        /// <param name="problemDetails">Contains the errors to be returned to the client.</param>
        public ErrorDetailsObjectResult(ErrorProblemDetails <T> problemDetails) : base(problemDetails)
        {
            if (problemDetails is null)
            {
                throw new ArgumentNullException(nameof(problemDetails));
            }

            StatusCode = problemDetails.Status;
        }
        public override void Write(Utf8JsonWriter writer, ErrorProblemDetails <T> value, JsonSerializerOptions options)
        {
            writer.WriteStartObject();
            WriteProblemDetails(writer, value, options);

            writer.WriteStartObject(ErrorDetails);
            WriteDictionary(writer, ToDictionaryWithType(value.ErrorDetails), options);
            writer.WriteEndObject();

            writer.WriteEndObject();
        }