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.Collections.Generic;
using System.ComponentModel; using System.ComponentModel;
using System.Reflection; using System.Reflection;
using System.Runtime.CompilerServices;
using ln.http.api.attributes; using ln.http.api.attributes;
using ln.http.exceptions; using ln.http.exceptions;
using ln.http.router; using ln.http.router;
@ -46,17 +47,16 @@ namespace ln.http.api
object result = methodInfo.Invoke(this, arguments); object result = methodInfo.Invoke(this, arguments);
if (!methodInfo.ReturnType.Equals(typeof(HttpResponse))) if (result is HttpResponse httpResponse)
{ return httpResponse;
if (!typeof(JSONValue).IsAssignableFrom(methodInfo.ReturnType))
{ if (result is JSONValue jsonResult)
if (!JSONMapper.DefaultMapper.Serialize(result, out JSONValue json)) return defaultResponseFactory().Content(jsonResult);
return HttpResponse.InternalServerError().Content("Method result could not be serialized");
if (!JSONMapper.DefaultMapper.Serialize(result, out JSONValue json))
result = json; return HttpResponse.InternalServerError().Content("Method result could not be serialized");
}
return defaultResponseFactory().Content((JSONValue)result); result = json;
}
return defaultResponseFactory().Content(result.ToString()); return defaultResponseFactory().Content(result.ToString());
} }

View File

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