[BUG] EventGridEvent data set to anonymous object is not serialized properly
See original GitHub issueDescribe the bug
When sending a message created using the following code:
new EventGridEvent()
{
Id = Guid.NewGuid().ToString(),
EventType = "namespace.events.ievent",
Data = new
{
MessageTypes = "...",
},
EventTime = DateTime.Now,
Subject = "subject-" + DateTime.Now.ToString(),
DataVersion = "2.0"
};
The message arriving to the subscribers has empty data property ( data: {}
).
Expected behavior
The message’s data property should contain serialized data.
Environment:
- Name and version of the Library package used: Microsoft.Azure.EventGrid 3.2.0
Issue Analytics
- State:
- Created 3 years ago
- Comments:19 (14 by maintainers)
Top Results From Across the Web
Why does Event Grid serialize my already serialized data?
If I deserialize without a type, it becomes an escaped string. I tried to read the data as JObject instead of EventGridEvent, but...
Read more >Casting object to Anonymous Types in C# - Mitch Valenta
In my test, I wanted to validate the data on one of the models in that anonymous type that is set in IActionResult's...
Read more >EventGridEvent Class (Azure.Messaging.EventGrid)
Gets or sets the event payload as BinaryData. Using BinaryData, one can deserialize the payload into rich data, or access the raw JSON...
Read more >Serialized anonymous classes using JsonUtility
I tried today to serialize an anonymous type, and it returns me an empty json object. It would be nice to be able...
Read more >Deserialize an Anonymous Type
This sample deserializes JSON into an anonymous type. ... Serialize a DataSet · Serialize Raw JSON value · Serialize Unindented JSON.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Data
property is of typeobject
which should be able to work with any type. IfJObject
is expected, that should be indicated in the documentation or the type would need to be explicit.Assigning
EventGridEvent.Data
aJObject
of your data object sounds like a leaking abstraction.Looking at the tests along with the project it seems POCO objects are sent but never verified if the Data part is actually received. Also, it appears a custom event mapping has to be provided to deserialize custom events.
Perhaps @jfggdl and the team could provide more information or update the documentation? Thank you.
Anonymous types are supported in the new Azure.Message.EventGrid package that is currently in beta.
Project Readme - https://github.com/Azure/azure-sdk-for-net/blob/master/sdk/eventgrid/Azure.Messaging.EventGrid/README.md