-
Notifications
You must be signed in to change notification settings - Fork 305
TaskOrchestrator re-serializes message payload using Newtonsoft.Json. #796
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Probably related to microsoft/durabletask-dotnet#36 |
You should be able to replace the built-in |
@ulvesked are you using durabletask-dotnet? If so, this issue will be addressed in the next preview. If you are not using durabletask-dotnet, then the default is Newtonsoft.Json. If you are intending to replace the default converter, you can look at my fix in how I set the converter during orchestrations: microsoft/durabletask-dotnet#45, specifically the changes to |
Hi @jviau, Do you have a code snippet that shows how to do this? Thank you, |
Thanks for your comments. I have worked around the issue by using my own ObjectSerializer.
https://gist.github.com/ulvesked/44a6fc30d8fd622671343100eef8f1ae I will keep it like this until the next preview, which hopefully has implemented the same serializer across the pipeline as @jviau wrote. |
@plamber to fully replace the converter in DurableTask, there are a several locations you need to perform that:
|
Closing as this is possible |
Hey, I wanted to share that I used the method described above by @jviau (thank you) |
Hi Ronen, I wonder if you could share some sample code that performs the replacement? I can't wrap my head around it yet. Thanks a lot! |
Yes, this is possible, but that seems like a lot of steps to reimplement. I've opened a PR to flow the property bag through to the task/activity layer, which allows for these serializers to become properties tracked in the dispatch context (see #963). If this change gets merged, you'll be able to replace them in middleware with the following: public static class TestExtensions
{
public static void UseSerializer(this DispatchMiddlewareContext context, DataConverter converter)
{
if (converter is not JsonDataConverter json)
{
json = new JsonDataConverterProxy(converter);
}
context.SetProperty<DataConverter>(converter);
context.SetProperty<JsonDataConverter>(json);
}
private sealed class JsonDataConverterProxy : JsonDataConverter
{
private readonly DataConverter _converter;
public JsonDataConverterProxy(DataConverter converter)
{
_converter = converter;
}
public override object Deserialize(string data, Type objectType)
=> _converter.Deserialize(data, objectType);
public override string Serialize(object value)
=> _converter.Serialize(value);
public override string Serialize(object value, bool formatted)
=> _converter.Serialize(value, formatted);
}
} NOTE: I haven't figured out how to just flow it from TaskHubClient, but that would be ideal, so we just need to set it in one place. I can't think of a great scenario where I'd want different serializers for different parts of the process |
Thank you @twsouthwick. This is highly appreciated. I am looking forward for the merged PR |
I get a JsonException when passing complex types from Orchestrator to Activity. The payload received in the TaskActivity is not compatible with System.Text.Json.
After investigation, it appears that the orchestrator re-serializes all messages using Newtonsoft.Json, with
TypeNameHandling = TypeNameHandling.Objects
. This results in a JSON payload that is not parseable using System.Text.Json (which is default for TaskActivity payload)The class that does the conversion:
https://github.com/Azure/durabletask/blob/main/src/DurableTask.Core/Serializing/JsonDataConverter.cs
Here is a sample project to demonstrate the issue: https://github.com/ulvesked/DurablePocoPayloadSample
And a corresponding SO question: https://stackoverflow.com/questions/73776121/json-serialization-fails-with-functioninputconverterexception-for-complex-types
My original payload:
The payload received in TaskActivity:
The text was updated successfully, but these errors were encountered: