Skip to content

Commit

Permalink
Merge pull request #1564 from json-api-dotnet/fix-operations-empty-re…
Browse files Browse the repository at this point in the history
…sult

Fixed: return empty object instead of data:null in operation results
  • Loading branch information
bkoelman committed Jun 19, 2024
2 parents 0941d7c + 81b82ad commit 5583e4d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,28 @@ public override void Write(Utf8JsonWriter writer, Document value, JsonSerializer
if (!value.Results.IsNullOrEmpty())
{
writer.WritePropertyName(AtomicResultsText);
WriteSubTree(writer, value.Results, options);
writer.WriteStartArray();

foreach (AtomicResultObject result in value.Results)
{
writer.WriteStartObject();

if (result.Data.IsAssigned)
{
writer.WritePropertyName(DataText);
WriteSubTree(writer, result.Data, options);
}

if (!result.Meta.IsNullOrEmpty())
{
writer.WritePropertyName(MetaText);
WriteSubTree(writer, result.Meta, options);
}

writer.WriteEndObject();
}

writer.WriteEndArray();
}

if (!value.Errors.IsNullOrEmpty())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,7 @@ public async Task Hides_data_for_void_operation()
"self": "http://localhost/operations"
},
"atomic:results": [
{
"data": null
},
{},
{
"data": {
"type": "textLanguages",
Expand Down

0 comments on commit 5583e4d

Please sign in to comment.