Class MessagePackOutputFormatter
- Namespace
- Nerdbank.MessagePack.AspNetCoreMvcFormatter
- Assembly
- Nerdbank.MessagePack.AspNetCoreMvcFormatter.dll
An output formatter for ASP.NET Core MVC that serializes strongly-typed objects into MessagePack content.
public class MessagePackOutputFormatter : OutputFormatter, IOutputFormatter, IApiResponseTypeMetadataProvider
- Inheritance
-
MessagePackOutputFormatter
- Implements
- Inherited Members
Remarks
This formatter supports the "application/x-msgpack" media type and uses the provided ITypeShapeProvider to resolve type shapes for serialization with the specified MessagePackSerializer.
Constructors
MessagePackOutputFormatter(ITypeShapeProvider)
Initializes a new instance of the MessagePackOutputFormatter class.
public MessagePackOutputFormatter(ITypeShapeProvider typeShapeProvider)
Parameters
typeShapeProviderITypeShapeProvider- The type shape provider used to resolve type shapes for serialization. This may be Default but is recommended to be a source generated type shape provider for better startup performance.
Remarks
The MessagePackSerializer this constructor initializes includes converters commonly useful to ASP.NET Core MVC scenarios, including WithObjectConverter(MessagePackSerializer).
MessagePackOutputFormatter(ITypeShapeProvider, MessagePackSerializer)
Initializes a new instance of the MessagePackOutputFormatter class with the specified MessagePack serializer.
public MessagePackOutputFormatter(ITypeShapeProvider typeShapeProvider, MessagePackSerializer serializer)
Parameters
typeShapeProviderITypeShapeProviderThe type shape provider used to resolve type shapes for serialization. This may be Default but is recommended to be a source generated type shape provider for better startup performance.
serializerMessagePackSerializerThe serializer to use.
Exceptions
- ArgumentNullException
Thrown when
serializeris null.
Methods
WriteResponseBodyAsync(OutputFormatterWriteContext)
Writes the response body.
public override Task WriteResponseBodyAsync(OutputFormatterWriteContext context)
Parameters
contextOutputFormatterWriteContextThe formatter context associated with the call.
Returns
- Task
A task which can write the response body.