I'm trying to make an API using .NET Core 3.1 with C# programming language which utilizes Firebase real-time database from Google through FireSharp Nu-Get package. When I ran it, I got this exception: System.Text.Json.JsonException: A possible object cycle was detected which is not supported. This can either be due to a cycle or if the object depth is larger than the maximum allowed depth of 32.
I read here that I can just install Microsoft.AspNetCore.Mvc.NewtonsoftJson package and ignore the reference loop handling, which works fine. But the data format looks unreadable, very hard to deserialize, and way too long:
{
"stateMachine": {
"<>1__state": 0,
"<>t__builder": {},
"bpjs": "12345678",
"reservationTime": "24-11-2020",
"<>4__this": {}
},
"context": {},
"moveNextAction": {
"method": {
"name": "MoveNext",
"declaringType": ...
...
((lots of irrelevant things))
...
}
},
"result": {
"queueNumber": "1",
"bpjs": "12345678",
"name": "Addi",
"poli": "Umum",
"reservationTime": "24-11-2020",
"status": "Queueing"
},
"id": 2,
"exception": null,
"status": 5,
"isCanceled": false,
"isCompleted": true,
"isCompletedSuccessfully": true,
"creationOptions": 0,
"asyncState": null,
"isFaulted": false}
Before this, I already tried to do some mapping and not directly use my data model by following this video's tutorial on doing DTOs, but it didn't work most likely because I don't use SQL Database.
Now I'm trying to use this API on a Flutter app. Is there anyway for me to maybe do some minor changes on my API code (anything that doesn't involve completely changing the database to SQL) to reformat my response? Or maybe a way to just partly deserialize my response, since I only need the "result" part and not anything else?
Edit:
This is my main code to get the data:
public async Task<QueueData> GetQueueData(string bpjs, string reservationTime)
{
//set up connection
IFirebaseConfig config = new FirebaseConfig
{
AuthSecret = myAuthSecret,
BasePath = myBasePath
};
IFirebaseClient client = new FireSharp.FirebaseClient(config);
//checkqueuenumber
string queueCounter = await QueueDbConnection.CheckQueueNumber(reservationTime, client);
//getresult
QueueData result = await QueueDbConnection.GetResult(bpjs, reservationTime, queueCounter, client);
return result;
}
this is my controller to call the function above:
[HttpGet("{bpjs}/{reservationTime}")]
public ActionResult<QueueData> GetQueueData(string bpjs, string reservationTime)
{
var queueData = _repository.GetQueueData(bpjs, reservationTime);
return Ok(queueData);
}
This is my model for the QueueData, which is the type I'm trying to return as response:
public class QueueData
{
[Required]
public string QueueNumber { get; set; }
[Required]
public string BPJS { get; set; }
[Required]
public string Name { get; set; }
[Required]
public string Poli { get; set; }
[Required]
public string ReservationTime { get; set; }
[Required]
public string Status { get; set; }
}
this is another model class called control to monitor the number of people queueing each day:
public class QueueCounter
{
[Required]
public string q { get; set; }
}