Azure ServiceBus extension for CloudNative.CloudEvents
The features provide by this package have been implemented officially after version 2.0. Please use CloudNative.CloudEvents.NewtonsoftJson.
Generic Json extension for CloudNative.CloudEvents
var jsonSerializerSettings = new JsonSerializerSettings
{
DateParseHandling = DateParseHandling.DateTimeOffset,
DateTimeZoneHandling = DateTimeZoneHandling.Utc,
};
var formatter = new JsonCloudEventFormatter<MyData>(jsonSerializerSettings); // JsonSerializerSettings is optional
var cloudEvent = formatter.DecodeStructuredEvent(jsonData);
cloudEvent.Data.Should().BeOfType<MyData>(); // The type of Data is MyData type, but not JToken
Notice
The attribute value may be a DateTimeOffset if the JsonSerializerSettings.DateParseHandling
is DateParseHandling.DateTimeOffset
. But the attribute value for time
will always be DateTime.