diff --git a/JSONAPI.Tests/Json/JsonApiMediaFormaterTests.cs b/JSONAPI.Tests/Json/JsonApiMediaFormaterTests.cs index fe2c7e96..747feee4 100644 --- a/JSONAPI.Tests/Json/JsonApiMediaFormaterTests.cs +++ b/JSONAPI.Tests/Json/JsonApiMediaFormaterTests.cs @@ -1,4 +1,5 @@ using System; +using System.Linq; using Microsoft.VisualStudio.TestTools.UnitTesting; using JSONAPI.Tests.Models; using Newtonsoft.Json; @@ -117,6 +118,31 @@ public void SerializerIntegrationTest() //Assert.AreEqual("[2,3,4]", sw.ToString()); } + [TestMethod] + [DeploymentItem(@"Data\SerializerIntegrationTest.json")] + public void SerializeArrayIntegrationTest() + { + // Arrange + //PayloadConverter pc = new PayloadConverter(); + //ModelConverter mc = new ModelConverter(); + //ContractResolver.PluralizationService = new PluralizationService(); + + JsonApiFormatter formatter = new JSONAPI.Json.JsonApiFormatter(); + formatter.PluralizationService = new JSONAPI.Core.PluralizationService(); + MemoryStream stream = new MemoryStream(); + + // Act + //Payload payload = new Payload(a.Posts); + //js.Serialize(jw, payload); + formatter.WriteToStreamAsync(typeof(Post), a.Posts.ToArray(), stream, (System.Net.Http.HttpContent)null, (System.Net.TransportContext)null); + + // Assert + string output = System.Text.Encoding.ASCII.GetString(stream.ToArray()); + Trace.WriteLine(output); + Assert.AreEqual(output.Trim(), File.ReadAllText("SerializerIntegrationTest.json").Trim()); + //Assert.AreEqual("[2,3,4]", sw.ToString()); + } + [TestMethod] public void DeserializeCollectionIntegrationTest() { diff --git a/JSONAPI/Json/JsonApiFormatter.cs b/JSONAPI/Json/JsonApiFormatter.cs index 774c7c41..62fad7e7 100644 --- a/JSONAPI/Json/JsonApiFormatter.cs +++ b/JSONAPI/Json/JsonApiFormatter.cs @@ -759,8 +759,9 @@ private bool IsMany(dynamic value = null) private bool IsMany(Type type) { - //TODO: Should we check for arrays also? (They aren't generics.) - return (type.GetInterfaces().Contains(typeof(IEnumerable)) && type.IsGenericType); + return + type.IsArray || + (type.GetInterfaces().Contains(typeof(IEnumerable)) && type.IsGenericType); } private Type GetSingleType(Type type)//dynamic value = null)