BsonDocument exceeds the JsonSerializerOptions.MaxDepth setting
Type
running the project returns
I'm using
I tried doing as well but nothing helps.
[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; }
}[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.System.InvalidOperationException: The depth of the generated JSON schema exceeds the JsonSerializerOptions.MaxDepth setting.I'm using
Scalar.AspNetCoreScalar.AspNetCore for this with default MapOpenApiMapOpenApiI tried doing as well but nothing helps.
builder.Services.AddControllers().AddJsonOptions(options =>
{
options.JsonSerializerOptions.MaxDepth = 256;
options.JsonSerializerOptions.ReferenceHandler = ReferenceHandler.IgnoreCycles;
});builder.Services.AddControllers().AddJsonOptions(options =>
{
options.JsonSerializerOptions.MaxDepth = 256;
options.JsonSerializerOptions.ReferenceHandler = ReferenceHandler.IgnoreCycles;
});