added protected to and from json methods

dev
Don Oerkfitz 4 years ago
parent 8c280213e9
commit fab692c15e

@ -1,6 +1,8 @@
using System.Collections.Generic; using System.Collections.Generic;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Text.Json;
using System.Text.Json.Serialization;
namespace OSI.API.Controllers namespace OSI.API.Controllers
{ {
@ -24,5 +26,30 @@ namespace OSI.API.Controllers
// DELETE: api/Clients/5 // DELETE: api/Clients/5
[HttpDelete("{id}")] [HttpDelete("{id}")]
public abstract IActionResult Delete(int id); public abstract IActionResult Delete(int id);
protected T FromJSON<T>(string input)
{
JsonSerializerOptions options = new()
{
Converters = {
new JsonStringEnumConverter()
}
};
return JsonSerializer.Deserialize<T>(input, options);
}
protected string ToJSON<T>(T input)
{
JsonSerializerOptions options = new()
{
WriteIndented = true,
Converters = {
new JsonStringEnumConverter()
}
};
return JsonSerializer.Serialize<T>(input, options);
}
} }
} }
Loading…
Cancel
Save