Here are 2 json response examples received when logging in...
For the successful response, payload is a class with id and name
{
"merchant": "test123",
"payload": {
"id": "1234",
"name": "Test"
},
"code": "100",
"message": "Request successfully executed"
}
...but if the response is unsuccessful I receive the following...
{
"merchant": "test123",
"payload": false,
"code": "105",
"message": "Invalid username or password!"
}
I have no control over receiving "payload": false. Ideally this would be "payload": null.
How can I change the "payload": false to "payload": null when deserializing the response? Currently getting an exception error at runtime. Using C# and refit.
using System.Text.Json;
namespace Response;
public class ResponseRoot
{
public string Merchant { get; set; }
//the value received in the json response needs to become null if the value is false?
public ResponsePayload? Payload { get; set; }
public string Code { get; set; }
public string Message { get; set; }
public class ResponsePayload
{
public string Id { get; set; }
public string Name { get; set; }
}
}
you can parse at first
if you have some time and desire you can wrap this code in a function or in a custom json converter.