C#C
C#11mo ago
Byte

BsonDocument exceeds the JsonSerializerOptions.MaxDepth setting

Type
[BsonCollection("product_categories")]
public class ProductCategory
{
    [BsonId(IdGenerator = typeof(StringObjectIdGenerator))]
    [BsonRepresentation(BsonType.ObjectId)]
    public string Id { get; set; } = null!;

    [BsonElement("name")]
    [BsonRequired]
    public required string Name { get; set; }
    
    [BsonElement("icon")]
    public ImageAsset? Icon { get; set; }
    
    [BsonElement("schema")]
    [BsonExtraElements]
    public required BsonDocument  Schema { get; set; }
    
    [BsonElement("is_active")]
    public bool IsActive { get; set; }
    
    [BsonElement("created_at")]
    [BsonRequired]
    public DateTime CreatedAt { get; set; }
    
    [BsonElement("updated_at")]
    [BsonRequired]
    public DateTime UpdatedAt { get; set; }
}


running the project returns System.InvalidOperationException: The depth of the generated JSON schema exceeds the JsonSerializerOptions.MaxDepth setting.

I'm using Scalar.AspNetCore for this with default MapOpenApi

I tried doing as well but nothing helps.
builder.Services.AddControllers().AddJsonOptions(options =>
{
    options.JsonSerializerOptions.MaxDepth = 256;
    options.JsonSerializerOptions.ReferenceHandler = ReferenceHandler.IgnoreCycles;
});
Was this page helpful?