diff --git a/ln.http.api/WebApiController.cs b/ln.http.api/WebApiController.cs index ba71a1c..c74ca9a 100644 --- a/ln.http.api/WebApiController.cs +++ b/ln.http.api/WebApiController.cs @@ -4,6 +4,7 @@ using System; using System.Collections.Generic; using System.ComponentModel; using System.Reflection; +using System.Runtime.CompilerServices; using ln.http.api.attributes; using ln.http.exceptions; using ln.http.router; @@ -46,17 +47,16 @@ namespace ln.http.api object result = methodInfo.Invoke(this, arguments); - if (!methodInfo.ReturnType.Equals(typeof(HttpResponse))) - { - if (!typeof(JSONValue).IsAssignableFrom(methodInfo.ReturnType)) - { - if (!JSONMapper.DefaultMapper.Serialize(result, out JSONValue json)) - return HttpResponse.InternalServerError().Content("Method result could not be serialized"); - - result = json; - } - return defaultResponseFactory().Content((JSONValue)result); - } + if (result is HttpResponse httpResponse) + return httpResponse; + + if (result is JSONValue jsonResult) + return defaultResponseFactory().Content(jsonResult); + + if (!JSONMapper.DefaultMapper.Serialize(result, out JSONValue json)) + return HttpResponse.InternalServerError().Content("Method result could not be serialized"); + + result = json; return defaultResponseFactory().Content(result.ToString()); } diff --git a/ln.http.api/ln.http.api.csproj b/ln.http.api/ln.http.api.csproj index bc2fe93..888d388 100644 --- a/ln.http.api/ln.http.api.csproj +++ b/ln.http.api/ln.http.api.csproj @@ -20,3 +20,4 @@ +