Skip to content

Commit 3cc0280

Browse files
author
Chris Santero
committed
only fetch link ID if link template requests it
1 parent f8cb642 commit 3cc0280

1 file changed

Lines changed: 3 additions & 2 deletions

File tree

JSONAPI/Json/JsonApiFormatter.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -319,8 +319,9 @@ protected void Serialize(object value, Stream writeStream, JsonWriter writer, Js
319319
break;
320320
case SerializeAsOptions.Link:
321321
if (lt == null) throw new JsonSerializationException("A property was decorated with SerializeAs(SerializeAsOptions.Link) but no LinkTemplate attribute was provided.");
322-
//TODO: Check for "{0}" in linkTemplate and (only) if it's there, get the Ids of all objects and "implode" them.
323-
string href = String.Format(lt, null, GetIdFor(value));
322+
323+
string linkId = lt.Contains("{0}") ? GetIdFor(value) : null;
324+
string href = String.Format(lt, null, linkId);
324325
//writer.WritePropertyName(ContractResolver._modelManager.GetJsonKeyForProperty(prop));
325326
//TODO: Support ids and type properties in "link" object
326327
writer.WriteStartObject();

0 commit comments

Comments
 (0)