'C# how to serialize property of type class Newtonsoft [duplicate]
public class Driver : BaseEntity
{
public string FirstName { get; set; }
public string LastName { get; set; }
public string FullName => $"{FirstName} {LastName}";
public Shift? Shift { get; set; }
public Car Car { get; set; }
public string Licence { get; set; }
public DateTime LicenceExpiery { get; set; }
}
public class Car : BaseEntity
{
public string Model { get; set; }
public string LicensePlate { get; set; }
public DateTime LicensePlateExpieryDate { get; set; }
public List<Driver> AssasignedDrivers { get; set; }
}
I have two classes like shown above and im trying to serialize them to json , im using Newtonsoft for serialization and deserialization , but when im trying to do so i'm getting the following exceptions :
Self referencing loop detected with type 'Taxi_Manager.Domain.Entities.Driver'. Path '[0].Car.AssasignedDrivers'.
Self referencing loop detected for property 'Car' with type 'Taxi_Manager.Domain.Entities.Car'. Path '[0].AssasignedDrivers[0]'.
what could be the problem ?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
