Skip to content

Commit 635e20f

Browse files
committed
fix(document-builder): do not include null relationships in compound doc
1 parent ec25664 commit 635e20f

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/JsonApiDotNetCore/Builders/DocumentBuilder.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,14 +169,21 @@ private List<DocumentData> _getIncludedEntities(ContextEntity contextEntity, IId
169169

170170
if (navigationEntity is IEnumerable)
171171
foreach (var includedEntity in (IEnumerable)navigationEntity)
172-
included.Add(_getIncludedEntity((IIdentifiable)includedEntity));
172+
_addIncludedEntity(included, (IIdentifiable)includedEntity);
173173
else
174-
included.Add(_getIncludedEntity((IIdentifiable)navigationEntity));
174+
_addIncludedEntity(included, (IIdentifiable)navigationEntity);
175175
});
176176

177177
return included;
178178
}
179179

180+
private void _addIncludedEntity(List<DocumentData> entities, IIdentifiable entity)
181+
{
182+
var includedEntity = _getIncludedEntity(entity);
183+
if(includedEntity != null)
184+
entities.Add(includedEntity);
185+
}
186+
180187
private DocumentData _getIncludedEntity(IIdentifiable entity)
181188
{
182189
if(entity == null) return null;

0 commit comments

Comments
 (0)