diff --git a/src/NJsonApiCore/Serialization/JsonApiTransformer.cs b/src/NJsonApiCore/Serialization/JsonApiTransformer.cs index 6e076be..6370455 100644 --- a/src/NJsonApiCore/Serialization/JsonApiTransformer.cs +++ b/src/NJsonApiCore/Serialization/JsonApiTransformer.cs @@ -54,7 +54,7 @@ public CompoundDocument Transform(object objectGraph, Context context) var result = new CompoundDocument { - Meta = transformationHelper.GetMetadata(objectGraph) + Meta = transformationHelper.GetTopLevelMetadata(objectGraph) }; var resource = transformationHelper.UnwrapResourceObject(objectGraph); diff --git a/src/NJsonApiCore/Serialization/TransformationHelper.cs b/src/NJsonApiCore/Serialization/TransformationHelper.cs index 86f47f7..3f41385 100644 --- a/src/NJsonApiCore/Serialization/TransformationHelper.cs +++ b/src/NJsonApiCore/Serialization/TransformationHelper.cs @@ -164,11 +164,11 @@ public object UnwrapResourceObject(object objectGraph) return objectGraph; } - public IMetaData GetMetadata(object objectGraph) + public IMetaData GetTopLevelMetadata(object objectGraph) { - if (objectGraph is IObjectMetaDataContainer) + if (objectGraph is ITopLevelDocument) { - var metaDataContainer = objectGraph as IObjectMetaDataContainer; + var metaDataContainer = objectGraph as ITopLevelDocument; return metaDataContainer.GetMetaData(); } return null; diff --git a/test/NJsonApiCore.Test/Serialization/JsonApiTransformerTest/TestMetaData.cs b/test/NJsonApiCore.Test/Serialization/JsonApiTransformerTest/TestMetaData.cs index f465c2d..d59f15c 100644 --- a/test/NJsonApiCore.Test/Serialization/JsonApiTransformerTest/TestMetaData.cs +++ b/test/NJsonApiCore.Test/Serialization/JsonApiTransformerTest/TestMetaData.cs @@ -48,6 +48,7 @@ public void Creates_CompoundDocument_for_single_class_with_metadata_and_properly var transformedObject = result.Data as SingleResource; Assert.Equal("value1", transformedObject.MetaData["meta1"]); Assert.Equal("value2", transformedObject.MetaData["meta2"]); + Assert.Null(result.Meta); } [Fact]