I have Azure Function running on .NET 8 with Isolated process type.
I have Service Bus queue trigger to listen queueA
and after processing I want to put message to other queue queueB
.
I have code like this:
[Function(nameof(HandleQueueA))]
[ServiceBusOutput(OutputQueueB, Connection = "ServiceBusConnection")]
public async Task<Envelope<JObject>> Run(
[ServiceBusTrigger(StartQueueA, Connection = "ServiceBusConnection")]
ServiceBusReceivedMessage message)
{
var eventData = JsonConvert.DeserializeObject<Envelope<JToken>>(message.Body);
// some logic here
return eventData;
}
Definition for Envelope
class is like:
public class Envelope<T>
{
public string Id { get; set; }
public DateTimeEpoch CreatedAt { get; set; }
public string EventInstance { get; set; }
public T Content { get; set; }
}
In JObject content here I have some business attributed for event itself.
And this works with no errors but at the end in queueB
I can see not fully serialized message like:
{
"Id": "<some-guid>",
"CreatedAt": {
"DateTime": "2024-07-30T15:14:38.5585185Z",
"Epoch": 1722352478
},
"EventInstance": "<some-guid>",
"Content": {
"attribute1": [],
"attribute2": [],
"some-collection1": [
[
[]
],
[
[]
]
],
"collection2": [
[
[]
],
[
[]
]
]
}
}
If I’m trying to serialize eventData
before returning from function, I can see correct data
If using Newtonsoft.Json.JsonConvert.SerializeObject(eventData)
:
"{"Id":"<some-guid>","createdAt":{"dateTime":"2024-07-30T15:40:12.5198266Z","epoch":1722354012},"content":{"attribute1":"attribute1Value","attribute2":"attribute2Value","some-collection1":{"name":"name","value":"value"},"collection2":{"name":"name","value":"value"}
I have the next global serialization settings:
JsonConvert.DefaultSettings = () => new JsonSerializerSettings()
{
DefaultValueHandling = DefaultValueHandling.Include,
NullValueHandling = NullValueHandling.Ignore,
ContractResolver = new CamelCasePropertyNamesContractResolver(),
Converters = new List<JsonConverter> { new StringEnumConverter(), new IsoDateTimeConverter() },
};
I would appreviate any ideas what’s wrong here 🙂
Thanks in advance!