Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -704,9 +704,7 @@ protected override void EncodeStructuredModeData(CloudEvent cloudEvent, Utf8Json

/// <inheritdoc />
protected override void DecodeStructuredModeDataProperty(JsonElement dataElement, CloudEvent cloudEvent) =>
// Note: this is an inefficient way of doing this.
// See https://github.com/dotnet/runtime/issues/31274 - when that's implemented, we can use the new method here.
cloudEvent.Data = JsonSerializer.Deserialize<T>(dataElement.GetRawText(), SerializerOptions);
cloudEvent.Data = JsonSerializer.Deserialize<T>(dataElement, SerializerOptions);

// TODO: Consider decoding the base64 data as a byte array, then using DecodeBinaryModeData.
/// <inheritdoc />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System.Net.Mime;
using System.Text;
using System.Text.Json;
using System.Text.Json.Serialization;
using Xunit;

namespace CloudNative.CloudEvents.SystemTextJson.UnitTests;
Expand Down Expand Up @@ -45,6 +46,22 @@ public void DecodeStructuredMode_ContentTypeIgnored()
Assert.Equal("test", model.AttributedProperty);
}

[Fact]
public void DecodeStructuredMode_UsesSerializerOptions()
{
var obj = JsonEventFormatterTest.CreateMinimalValidJObject();
obj["data"] = "10";
byte[] bytes = Encoding.UTF8.GetBytes(obj.ToString());

var formatter = new JsonEventFormatter<int>(new JsonSerializerOptions
{
NumberHandling = JsonNumberHandling.AllowReadingFromString
}, default);
var cloudEvent = formatter.DecodeStructuredModeMessage(bytes, null, null);

Assert.Equal(10, cloudEvent.Data);
}

[Fact]
public void DecodeStructuredMode_NoData()
{
Expand Down
Loading