diff --git a/JSONAPI.Tests/Core/ModelManagerTests.cs b/JSONAPI.Tests/Core/ModelManagerTests.cs index 5bbe7198..5190c462 100644 --- a/JSONAPI.Tests/Core/ModelManagerTests.cs +++ b/JSONAPI.Tests/Core/ModelManagerTests.cs @@ -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] diff --git a/JSONAPI/Core/ModelManager.cs b/JSONAPI/Core/ModelManager.cs index 5dc49bcc..78724466 100644 --- a/JSONAPI/Core/ModelManager.cs +++ b/JSONAPI/Core/ModelManager.cs @@ -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;