Skip to content

Commit dc5cc3c

Browse files
author
Chris Santero
committed
refactor writing resource identifier objects
1 parent 31247c3 commit dc5cc3c

1 file changed

Lines changed: 10 additions & 7 deletions

File tree

JSONAPI/Json/JsonApiFormatter.cs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -336,10 +336,8 @@ protected void Serialize(object value, Stream writeStream, JsonWriter writer, Js
336336

337337
Lazy<string> objId = new Lazy<String>(() => GetIdFor(propertyValue));
338338

339-
// Write the data object
340-
writer.WriteStartObject();
341-
WriteTypeAndId(writer, prop.PropertyType, propertyValue);
342-
writer.WriteEndObject();
339+
// Write the resource identifier object
340+
WriteResourceIdentifierObject(writer, prop.PropertyType, propertyValue);
343341

344342
if (iip)
345343
if (aggregator != null)
@@ -962,6 +960,13 @@ protected string GetIdFor(object obj)
962960
return GetValueForIdProperty(idprop, obj);
963961
}
964962

963+
private void WriteResourceIdentifierObject(JsonWriter writer, Type propertyType, object propertyValue)
964+
{
965+
writer.WriteStartObject();
966+
WriteTypeAndId(writer, propertyType, propertyValue);
967+
writer.WriteEndObject();
968+
}
969+
965970
private void WriteTypeAndId(JsonWriter writer, Type propertyType, object propertyValue)
966971
{
967972
writer.WritePropertyName("type");
@@ -977,9 +982,7 @@ private void WriteIdsArrayJson(Newtonsoft.Json.JsonWriter writer, IEnumerable<ob
977982
writer.WriteStartArray();
978983
while (collectionEnumerator.MoveNext())
979984
{
980-
writer.WriteStartObject();
981-
WriteTypeAndId(writer, collectionEnumerator.Current.GetType(), collectionEnumerator.Current);
982-
writer.WriteEndObject();
985+
WriteResourceIdentifierObject(writer, collectionEnumerator.Current.GetType(), collectionEnumerator.Current);
983986
}
984987
writer.WriteEndArray();
985988
}

0 commit comments

Comments
 (0)