I can't serialize BaseResponse<NoContent>
object. But Device
object serialized successfully. I didnt find reason
var data = new BaseResponse<NoContent>();
var json1 = JsonSerializer.Serialize(data);
var data2 = new Device();
var json2 = JsonSerializer.Serialize(data2);
BaseResponse
Content :
public class BaseResponse<T> where T : class, new()
{
public BaseResponse()
{
Data = new T();
}
public T Data;
public string Status = "Success";
public List<string> Errors;
public BaseResponse<T> AddError(string message)
{
Errors ??= new List<string>();
Status = "Error";
Errors.Add(message);
return this;
}
}
Edit: Newtonsoft.Json can serialize both of them. I decided use Newtonsoft.