diff --git a/src/Microsoft.AspNet.Mvc.Core/ActionResults/ObjectResult.cs b/src/Microsoft.AspNet.Mvc.Core/ActionResults/ObjectResult.cs
index 69fd10e367..a6a47e9d81 100644
--- a/src/Microsoft.AspNet.Mvc.Core/ActionResults/ObjectResult.cs
+++ b/src/Microsoft.AspNet.Mvc.Core/ActionResults/ObjectResult.cs
@@ -94,8 +94,9 @@ namespace Microsoft.AspNet.Mvc
foreach (var formatter in formatters)
{
var supportedContentTypes = formatter.GetSupportedContentTypes(
- GetObjectType(formatterContext),
- contentType: null);
+ formatterContext.DeclaredType,
+ formatterContext.Object?.GetType(),
+ contentType: null);
if (formatter.CanWriteResult(formatterContext, supportedContentTypes?.FirstOrDefault()))
{
@@ -218,18 +219,5 @@ namespace Microsoft.AspNet.Mvc
return formatters;
}
-
- private Type GetObjectType([NotNull] OutputFormatterContext context)
- {
- if (context.DeclaredType == null || context.DeclaredType == typeof(object))
- {
- if (context.Object != null)
- {
- return context.Object.GetType();
- }
- }
-
- return context.DeclaredType;
- }
}
}
\ No newline at end of file
diff --git a/src/Microsoft.AspNet.Mvc.Core/Formatters/IOutputFormatter.cs b/src/Microsoft.AspNet.Mvc.Core/Formatters/IOutputFormatter.cs
index 5a43ecd975..9d04e598b7 100644
--- a/src/Microsoft.AspNet.Mvc.Core/Formatters/IOutputFormatter.cs
+++ b/src/Microsoft.AspNet.Mvc.Core/Formatters/IOutputFormatter.cs
@@ -20,12 +20,13 @@ namespace Microsoft.AspNet.Mvc
{
///
/// Gets a filtered list of content types which are supported by this formatter
- /// for the and .
+ /// for the and .
///
- /// Type for which the supported content types are desired.
+ /// The declared type for which the supported content types are desired.
+ /// The runtime type for which the supported content types are desired.
/// Content type for which the supported content types are desired.
- /// Content types which can are supported by this formatter.
- IReadOnlyList GetSupportedContentTypes(Type dataType, MediaTypeHeaderValue contentType);
+ /// Content types which are supported by this formatter.
+ IReadOnlyList GetSupportedContentTypes(Type declaredType, Type instanceType, MediaTypeHeaderValue contentType);
///
/// Determines whether this can serialize
diff --git a/src/Microsoft.AspNet.Mvc.Core/Formatters/NoContentFormatter.cs b/src/Microsoft.AspNet.Mvc.Core/Formatters/NoContentFormatter.cs
index 9ba33c9d44..5d2ab6e833 100644
--- a/src/Microsoft.AspNet.Mvc.Core/Formatters/NoContentFormatter.cs
+++ b/src/Microsoft.AspNet.Mvc.Core/Formatters/NoContentFormatter.cs
@@ -21,7 +21,7 @@ namespace Microsoft.AspNet.Mvc
return context.Object == null;
}
- public IReadOnlyList GetSupportedContentTypes(Type dataType, MediaTypeHeaderValue contentType)
+ public IReadOnlyList GetSupportedContentTypes(Type declaredType, Type runtimeType, MediaTypeHeaderValue contentType)
{
return null;
}
diff --git a/src/Microsoft.AspNet.Mvc.Core/Formatters/OutputFormatter.cs b/src/Microsoft.AspNet.Mvc.Core/Formatters/OutputFormatter.cs
index 438f21e099..4237214a2d 100644
--- a/src/Microsoft.AspNet.Mvc.Core/Formatters/OutputFormatter.cs
+++ b/src/Microsoft.AspNet.Mvc.Core/Formatters/OutputFormatter.cs
@@ -40,7 +40,7 @@ namespace Microsoft.AspNet.Mvc
public IList SupportedMediaTypes { get; private set; }
///
- public virtual IReadOnlyList GetSupportedContentTypes(Type dataType, MediaTypeHeaderValue contentType)
+ public virtual IReadOnlyList GetSupportedContentTypes(Type declaredType, Type runtimeType, MediaTypeHeaderValue contentType)
{
var mediaTypes = new List();
diff --git a/test/Microsoft.AspNet.Mvc.Core.Test/ActionResults/ObjectResultTests.cs b/test/Microsoft.AspNet.Mvc.Core.Test/ActionResults/ObjectResultTests.cs
index bfee0fccfd..43d21f8f17 100644
--- a/test/Microsoft.AspNet.Mvc.Core.Test/ActionResults/ObjectResultTests.cs
+++ b/test/Microsoft.AspNet.Mvc.Core.Test/ActionResults/ObjectResultTests.cs
@@ -550,7 +550,8 @@ namespace Microsoft.AspNet.Mvc.Core.Test.ActionResults
return false;
}
- public IReadOnlyList GetSupportedContentTypes(Type dataType,
+ public IReadOnlyList GetSupportedContentTypes(Type declaredType,
+ Type runtimeType,
MediaTypeHeaderValue contentType)
{
return null;
diff --git a/test/Microsoft.AspNet.Mvc.Core.Test/JsonResultTest.cs b/test/Microsoft.AspNet.Mvc.Core.Test/JsonResultTest.cs
index 28931ecaa6..57666f66dc 100644
--- a/test/Microsoft.AspNet.Mvc.Core.Test/JsonResultTest.cs
+++ b/test/Microsoft.AspNet.Mvc.Core.Test/JsonResultTest.cs
@@ -118,7 +118,8 @@ namespace Microsoft.AspNet.Mvc
return true;
}
- public IReadOnlyList GetSupportedContentTypes(Type dataType,
+ public IReadOnlyList GetSupportedContentTypes(Type declaredType,
+ Type runtimeType,
MediaTypeHeaderValue contentType)
{
return null;
diff --git a/test/Microsoft.AspNet.Mvc.Core.Test/OptionDescriptors/OutputFormatterDescriptorTest.cs b/test/Microsoft.AspNet.Mvc.Core.Test/OptionDescriptors/OutputFormatterDescriptorTest.cs
index 78cff7970d..0a4affb277 100644
--- a/test/Microsoft.AspNet.Mvc.Core.Test/OptionDescriptors/OutputFormatterDescriptorTest.cs
+++ b/test/Microsoft.AspNet.Mvc.Core.Test/OptionDescriptors/OutputFormatterDescriptorTest.cs
@@ -62,7 +62,8 @@ namespace Microsoft.AspNet.Mvc.Core
throw new NotImplementedException();
}
- public IReadOnlyList GetSupportedContentTypes(Type dataType,
+ public IReadOnlyList GetSupportedContentTypes(Type declaredType,
+ Type runtimeType,
MediaTypeHeaderValue contentType)
{
return null;
diff --git a/test/WebSites/ConnegWebSite/Controllers/FallbackOnTypeBasedMatchController.cs b/test/WebSites/ConnegWebSite/Controllers/FallbackOnTypeBasedMatchController.cs
index b200d7de49..8e233e0ce5 100644
--- a/test/WebSites/ConnegWebSite/Controllers/FallbackOnTypeBasedMatchController.cs
+++ b/test/WebSites/ConnegWebSite/Controllers/FallbackOnTypeBasedMatchController.cs
@@ -74,7 +74,7 @@ namespace ConnegWebsite
return contentType == null;
}
- public IReadOnlyList GetSupportedContentTypes(Type dataType, MediaTypeHeaderValue contentType)
+ public IReadOnlyList GetSupportedContentTypes(Type declaredType, Type runtimeType, MediaTypeHeaderValue contentType)
{
return null;
}