private static void WriteException(Utf8JsonWriter writer, IDictionary <string, object> exception, int depth, ExceptionProblemDetailsOptions exceptionDetailsOptions, JsonSerializerOptions jsonOptions)
        {
            foreach (var item in exception)
            {
                if (item.Key.Equals(ExceptionProblemDetails.TypeKey))
                {
                    if (!jsonOptions.IgnoreNullValues || item.Value != null)
                    {
                        writer.WriteString(ExceptionType, (string)item.Value);
                    }
                }
                if (exceptionDetailsOptions.Details >= DetailLevel.Moderate)
                {
                    if (item.Key.Equals(ExceptionProblemDetails.MessageKey))
                    {
                        if (!jsonOptions.IgnoreNullValues || item.Value != null)
                        {
                            writer.WriteString(ExceptionMessage, (string)item.Value);
                        }
                    }

                    if (exceptionDetailsOptions.Details >= DetailLevel.Full)
                    {
                        if (item.Key.Equals(ExceptionProblemDetails.StackTraceKey))
                        {
                            if (!jsonOptions.IgnoreNullValues || item.Value != null)
                            {
                                writer.WriteString(ExceptionStackTrace, (string)item.Value);
                            }
                        }
                    }
                }

                if (item.Key.Equals(ExceptionProblemDetails.ExceptionsKey) && depth < exceptionDetailsOptions.Depth - 1)
                {
                    if (item.Value is IList <IDictionary <string, object> > innerList)
                    {
                        writer.WritePropertyName(ExceptionExceptions);
                        writer.WriteStartArray();
                        foreach (var innerItem in innerList)
                        {
                            writer.WriteStartObject();
                            WriteException(writer, innerItem, depth + 1, exceptionDetailsOptions, jsonOptions);
                            writer.WriteEndObject();
                        }
                        writer.WriteEndArray();
                    }
                }
            }
        }
 public ExceptionProblemDetailsJsonConverter(ExceptionProblemDetailsOptions options)
 {
     _exceptionDetailsOptions = options ?? new ExceptionProblemDetailsOptions();
 }