diff --git a/backend/ResQueue/ResQueue/Endpoints/QueueEndpoints.cs b/backend/ResQueue/ResQueue/Endpoints/QueueEndpoints.cs index 49ff802..7bc9464 100644 --- a/backend/ResQueue/ResQueue/Endpoints/QueueEndpoints.cs +++ b/backend/ResQueue/ResQueue/Endpoints/QueueEndpoints.cs @@ -48,7 +48,7 @@ public static void MapQueueEndpoints(this IEndpointRouteBuilder routes) return Results.Ok(queues.Select(x => new QueueDto() { Id = x.Id.ToString(), - RawData = x.RawData.ToString(), + RawData = JsonHelper.ConvertBsonToJson(x.RawData), TotalMessages = x.TotalMessages, IsFavorite = x.IsFavorite, CreatedAt = x.CreatedAt @@ -137,7 +137,7 @@ public static void MapQueueEndpoints(this IEndpointRouteBuilder routes) Items = queues.Select(x => new QueueDto() { Id = x.Id.ToString(), - RawData = x.RawData.ToString(), + RawData = JsonHelper.ConvertBsonToJson(x.RawData), TotalMessages = x.TotalMessages, IsFavorite = x.IsFavorite, CreatedAt = x.CreatedAt diff --git a/backend/ResQueue/ResQueue/JsonHelper.cs b/backend/ResQueue/ResQueue/JsonHelper.cs new file mode 100644 index 0000000..529830e --- /dev/null +++ b/backend/ResQueue/ResQueue/JsonHelper.cs @@ -0,0 +1,20 @@ +using MongoDB.Bson; +using MongoDB.Bson.IO; + +namespace ResQueue; + +public static class JsonHelper +{ + public static string ConvertBsonToJson(BsonDocument bsonDocument) + { + // Relaxed converts Int64 to a standard number representation in JSON + // instead of MongoDB-specific types like NumberLong(), ensuring + // compatibility with JSON parsers that expect standard number types. + + // This mode also normalizes other BSON types, like dates and binary data, + // into formats that work seamlessly in typical JSON contexts. + + var jsonSettings = new JsonWriterSettings { OutputMode = JsonOutputMode.RelaxedExtendedJson }; + return bsonDocument.ToJson(jsonSettings); + } +} \ No newline at end of file