Skip to content

Commit 1b80f05

Browse files
committed
fix(JsonApiDeserializer): NullReferenceException
don't do unnecessary work if no relationships were included
1 parent 3528e1f commit 1b80f05

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

src/JsonApiDotNetCore/Serialization/JsonApiDeSerializer.cs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -215,12 +215,15 @@ private object SetHasOneRelationship(object entity,
215215
SetHasOneNavigationPropertyValue(entity, attr, rio, included);
216216

217217
// recursive call ...
218-
var navigationPropertyValue = attr.GetValue(entity);
219-
var contextGraphEntity = _jsonApiContext.ContextGraph.GetContextEntity(attr.Type);
220-
if(navigationPropertyValue != null && contextGraphEntity != null)
218+
if(included != null)
221219
{
222-
var includedResource = included.Single(r => r.Type == rio.Type && r.Id == rio.Id);
223-
SetRelationships(navigationPropertyValue, contextGraphEntity, includedResource.Relationships, included);
220+
var navigationPropertyValue = attr.GetValue(entity);
221+
var contextGraphEntity = _jsonApiContext.ContextGraph.GetContextEntity(attr.Type);
222+
if(navigationPropertyValue != null && contextGraphEntity != null)
223+
{
224+
var includedResource = included.Single(r => r.Type == rio.Type && r.Id == rio.Id);
225+
SetRelationships(navigationPropertyValue, contextGraphEntity, includedResource.Relationships, included);
226+
}
224227
}
225228

226229
return entity;

0 commit comments

Comments
 (0)