Skip to content

Commit ed6ebc0

Browse files
committed
fix(output-formatter): do not serialize non-JsonAPI objects as JSONAPI
1 parent 00b71d7 commit ed6ebc0

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

src/JsonApiDotNetCore/Formatters/JsonApiOutputFormatter.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,17 +42,18 @@ public async Task WriteAsync(OutputFormatterWriteContext context)
4242
string responseContent;
4343
try
4444
{
45-
if(context.Object.GetType() == typeof(Error))
45+
if(context.Object.GetType() == typeof(Error) || jsonApiContext.RequestEntity == null)
4646
{
47-
logger?.LogInformation("Response was type <Error>. Serializing as plain JSON.");
47+
logger?.LogInformation("Response was not a JSONAPI entity. Serializing as plain JSON.");
48+
4849
responseContent = JsonConvert.SerializeObject(context.Object);
4950
}
5051
else
5152
responseContent = JsonApiSerializer.Serialize(context.Object, jsonApiContext);
5253
}
5354
catch(Exception e)
5455
{
55-
logger?.LogError("An error ocurred while formatting the response.", e);
56+
logger?.LogError(new EventId(), e, "An error ocurred while formatting the response");
5657
responseContent = new Error("400", e.Message).GetJson();
5758
response.StatusCode = 400;
5859
}

src/JsonApiDotNetCore/project.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"version": "0.2.5",
2+
"version": "0.2.6",
33

44
"dependencies": {
55
"Microsoft.NETCore.App": {

0 commit comments

Comments
 (0)