Class JsonMessageSerializer
- Namespace
- Silverback.Messaging.Serialization
- Assembly
- Silverback.Integration.dll
Serializes the messages as JSON.
public sealed class JsonMessageSerializer : IMessageSerializer, IEquatable<JsonMessageSerializer>
- Inheritance
-
JsonMessageSerializer
- Implements
- Inherited Members
Constructors
JsonMessageSerializer(JsonSerializerOptions?, bool?)
Initializes a new instance of the JsonMessageSerializer class.
public JsonMessageSerializer(JsonSerializerOptions? options = null, bool? mustSetTypeHeader = null)
Parameters
optionsJsonSerializerOptionsThe JsonSerializer options.
mustSetTypeHeaderbool?A value indicating whether the message type header (see MessageType) must be set.
Properties
MustSetTypeHeader
Gets a value indicating whether the message type header (see MessageType) must be set. This is necessary when sending multiple message type through the same endpoint, to allow Silverback to automatically figure out the correct type to deserialize into.
public bool MustSetTypeHeader { get; }
Property Value
Options
Gets the JsonSerializer options.
public JsonSerializerOptions? Options { get; }
Property Value
Methods
Equals(JsonMessageSerializer?)
public bool Equals(JsonMessageSerializer? other)
Parameters
otherJsonMessageSerializer
Returns
Equals(object?)
public override bool Equals(object? obj)
Parameters
objobject
Returns
GetHashCode()
public override int GetHashCode()
Returns
SerializeAsync(object?, MessageHeaderCollection, ProducerEndpoint)
Serializes the specified message object into a byte array.
public ValueTask<Stream?> SerializeAsync(object? message, MessageHeaderCollection headers, ProducerEndpoint endpoint)
Parameters
messageobjectThe message object to be serialized.
headersMessageHeaderCollectionThe message headers collection.
endpointProducerEndpointThe endpoint.
Returns
- ValueTask<Stream>
A Task<TResult> representing the asynchronous operation. The task result contains the Stream with the serialized message.