HangfireIO / HangfireIO/Hangfire

It is necessary to separate JsonSerializerSettings to serialize arguments and job results.

Open
#1,633 8 comments 1 reaction 0 assignees View on GitHub
Dominant language
C#
Stars
10.1k
Forks
1.8k
Avg merge
1h 19m
Merged PRs (30d)
1

Description

@odinserj, Hello! Thank you for the great project.
However, it is necessary to separate JsonSerializerSettings for Job arguments and results.
Otherwise, there's a case where things are very bad. How to reproduce:

1. Let's imagine that there is the following task. It requires an interface as an argument (and this is normal):
```csharp
public async Task GetSomethingAsync(IInterfaceArgument interfaceArgument)
{
// Use interfaceArgument here for get task results...
// return SomeResultDto instance here.
}
```
2. Now let's configure Hangfire so that it can use parameters that the interface requires. Specifically, we will configure Newtonsoft.Json so that it stores the type of interface implementation together:
```csharp
GlobalConfiguration.Configuration.UseSerializerSettings(new JsonSerializerSettings
{
TypeNameHandling = TypeNameHandling.Auto // For storing interface implementation types in json.
});
```
3. Now we use Hangfire to do the job with the `GetSomethingAsync` task.
4. That's great, now you can use tasks with interface arguments. But there is a big problem! The same JsonSerializerSettings is used to serialize job **RESULTS**, so we have an awfully heaped result that breaks client applications that are not ready for it.

So, we need to implement a separate JsonSerializerSettings to serialize the results and job arguments, otherwise by setting up JsonSerializerSettings for job arguments we break the serialization of the **results**.

Contributor guide

Open the contributing guide

Research direction

Start at GlobalConfiguration.Configuration.UseSerializerSettings and trace how the configured Newtonsoft.Json settings are used for job arguments and results. Define separate settings for those paths, then verify that interface argument types remain supported without changing the serialized shape of job results for existing clients.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
backend
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.