Skip to content

Commit

Permalink
fix jsonserialization bug, app is now revived phew
Browse files Browse the repository at this point in the history
  • Loading branch information
LeoFjatstrom committed Oct 6, 2024
1 parent 98b9cb7 commit 36f5209
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 8 deletions.
2 changes: 2 additions & 0 deletions Nexpo/Models/Notification.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Text.Json.Serialization;

namespace Nexpo.Models
{
Expand All @@ -10,6 +11,7 @@ public class Notification
public DateTime? ScheduledTime { get; set; }
public NotificationType NotificationType { get; set; }
public int? EventId { get; set; }
[JsonIgnore]
public ICollection<UserNotification> UserNotifications { get; set; }
}
}
1 change: 1 addition & 0 deletions Nexpo/Models/User.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public class User

public string profilePictureUrl { get; set; }

[JsonIgnore]
public ICollection<UserNotification> UserNotifications { get; set; }
public Guid Uuid { get; set; } = Guid.NewGuid();
public string ExpoPushToken { get; set; }
Expand Down
7 changes: 7 additions & 0 deletions Nexpo/Models/UserNotification.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
using System.Text.Json.Serialization;

namespace Nexpo.Models
{
public class UserNotification
{
public int UserId { get; set; }

[JsonIgnore]
public User User { get; set; }

public int NotificationId { get; set; }

[JsonIgnore]
public Notification Notification { get; set; }
}
}
9 changes: 1 addition & 8 deletions Nexpo/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,7 @@ public Startup(IConfiguration configuration, IWebHostEnvironment environment)
public void ConfigureServices(IServiceCollection services)
{

services.AddControllers()
.AddJsonOptions(options =>
{
// Traps for circular references of json
options.JsonSerializerOptions.ReferenceHandler = System.Text.Json.Serialization.ReferenceHandler.Preserve;
options.JsonSerializerOptions.DefaultIgnoreCondition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingNull;
options.JsonSerializerOptions.MaxDepth = 64;
});
services.AddControllers();

services.AddRouting(options =>
{
Expand Down

0 comments on commit 36f5209

Please sign in to comment.