WebApiController: Fix return value mapping
ln.build - build0.waldrennach.l--n.de build job pending Details

master
Harald Wolff 2020-12-11 10:44:44 +01:00
parent 133656cad1
commit 7faf05f4aa
2 changed files with 12 additions and 11 deletions

View File

@ -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());
}

View File

@ -20,3 +20,4 @@
</ItemGroup>
</Project>