Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions JSONAPI.Tests/Core/ModelManagerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,13 @@ public void GetJsonKeyForTypeTest()
var postKey = mm.GetJsonKeyForType(typeof(Post));
var authorKey = mm.GetJsonKeyForType(typeof(Author));
var commentKey = mm.GetJsonKeyForType(typeof(Comment));
var manyCommentKey = mm.GetJsonKeyForType(typeof(Comment[]));

// Assert
Assert.AreEqual("posts", postKey);
Assert.AreEqual("authors", authorKey);
Assert.AreEqual("comments", commentKey);
Assert.AreEqual("comments", manyCommentKey);
}

[TestMethod]
Expand Down
4 changes: 2 additions & 2 deletions JSONAPI/Core/ModelManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -127,11 +127,11 @@ public string GetJsonKeyForType(Type type)

lock (keyCache)
{
if (keyCache.TryGetValue(type, out key)) return key;

if (IsSerializedAsMany(type))
type = GetElementType(type);

if (keyCache.TryGetValue(type, out key)) return key;

var attrs = type.CustomAttributes.Where(x => x.AttributeType == typeof(Newtonsoft.Json.JsonObjectAttribute)).ToList();

string title = type.Name;
Expand Down