diff --git a/OSI-API/Controllers/_EndpointBase.cs b/OSI-API/Controllers/_EndpointBase.cs index 1ca6576..6444968 100644 --- a/OSI-API/Controllers/_EndpointBase.cs +++ b/OSI-API/Controllers/_EndpointBase.cs @@ -1,6 +1,8 @@ using System.Collections.Generic; using Microsoft.AspNetCore.Mvc; using System.Threading.Tasks; +using System.Text.Json; +using System.Text.Json.Serialization; namespace OSI.API.Controllers { @@ -24,5 +26,30 @@ namespace OSI.API.Controllers // DELETE: api/Clients/5 [HttpDelete("{id}")] public abstract IActionResult Delete(int id); + + protected T FromJSON(string input) + { + JsonSerializerOptions options = new() + { + Converters = { + new JsonStringEnumConverter() + } + }; + + return JsonSerializer.Deserialize(input, options); + } + + protected string ToJSON(T input) + { + JsonSerializerOptions options = new() + { + WriteIndented = true, + Converters = { + new JsonStringEnumConverter() + } + }; + + return JsonSerializer.Serialize(input, options); + } } } \ No newline at end of file