diff --git a/JSONAPI.Tests/Data/OverrideSerializationAttributesTest.json b/JSONAPI.Tests/Data/OverrideSerializationAttributesTest.json
new file mode 100644
index 00000000..074bf20a
--- /dev/null
+++ b/JSONAPI.Tests/Data/OverrideSerializationAttributesTest.json
@@ -0,0 +1,17 @@
+{
+ "posts": {
+ "id": "2",
+ "title": "How to fry an egg",
+ "links": {
+ "author": "5"
+ }
+ },
+ "linked": {
+ "users": [
+ {
+ "id": "5",
+ "name": "Bob"
+ }
+ ]
+ }
+}
\ No newline at end of file
diff --git a/JSONAPI.Tests/JSONAPI.Tests.csproj b/JSONAPI.Tests/JSONAPI.Tests.csproj
index d61bedf1..e6ebb4ba 100644
--- a/JSONAPI.Tests/JSONAPI.Tests.csproj
+++ b/JSONAPI.Tests/JSONAPI.Tests.csproj
@@ -109,6 +109,9 @@
Always
+
+ Always
+
Always
diff --git a/JSONAPI.Tests/Json/LinkTemplateTests.cs b/JSONAPI.Tests/Json/LinkTemplateTests.cs
index e5eb0d83..3dff8f47 100644
--- a/JSONAPI.Tests/Json/LinkTemplateTests.cs
+++ b/JSONAPI.Tests/Json/LinkTemplateTests.cs
@@ -61,7 +61,33 @@ public void GetResourceWithLinkTemplateRelationship()
var expected = JsonHelpers.MinifyJson(File.ReadAllText("LinkTemplateTest.json"));
var output = Encoding.ASCII.GetString(stream.ToArray());
Trace.WriteLine(output);
- Assert.AreEqual(output.Trim(), expected);
+ Assert.AreEqual(expected,output.Trim());
+ }
+
+ [TestMethod]
+ [DeploymentItem(@"Data\OverrideSerializationAttributesTest.json")]
+ public void OverrideSerializationAttributesTest()
+ {
+ // Arrange
+ var formatter = new JsonApiFormatter
+ (
+ new JSONAPI.Core.PluralizationService()
+ );
+ var stream = new MemoryStream();
+
+ // Act
+ JSONAPI.Core.MetadataManager.Instance.SetPropertyAttributeOverrides(
+ ThePost, typeof(Post).GetProperty("Author"),
+ new SerializeAs(SerializeAsOptions.Ids),
+ new IncludeInPayload(true)
+ );
+ formatter.WriteToStreamAsync(typeof(Post), ThePost, stream, null, null);
+
+ // Assert
+ var expected = JsonHelpers.MinifyJson(File.ReadAllText("OverrideSerializationAttributesTest.json"));
+ var output = Encoding.ASCII.GetString(stream.ToArray());
+ Trace.WriteLine(output);
+ Assert.AreEqual(expected, output.Trim());
}
}
}
diff --git a/JSONAPI/Core/MetadataManager.cs b/JSONAPI/Core/MetadataManager.cs
index d1541d52..2dbe5bd4 100644
--- a/JSONAPI/Core/MetadataManager.cs
+++ b/JSONAPI/Core/MetadataManager.cs
@@ -10,6 +10,23 @@ namespace JSONAPI.Core
{
public sealed class MetadataManager
{
+ private class PropertyMetadata
+ {
+ public bool PresentInJson { get; set; } // only meaningful for incoming/deserialized models!
+ public Lazy> AttributeOverrides
+ = new Lazy>(
+ () => new HashSet()
+ );
+ }
+
+ private class ModelMetadata
+ {
+ public Lazy> PropertyMetadata
+ = new Lazy>(
+ () => new Dictionary()
+ );
+ }
+
#region Singleton pattern
private static readonly MetadataManager instance = new MetadataManager();
@@ -26,8 +43,8 @@ public static MetadataManager Instance
#endregion
- private readonly ConditionalWeakTable