Description
name: Make JSON Serialize/Deserialize options user configurable for KernelProcessStepStateMetadata
about: Allow the json options to be defined and set by the calling code for restoration of process execution state
Some context for the problem:
Processes state can be restored via a prior state by passing in KernelProcessStateMetadata when building a process, ex:
ProcessBuilder builder = new ProcessBuilder("ProcessName");
// add steps, event mapping, etc.
KernelProcess kernelProcessWithPriorState = builder.Build(stateMetadata: priorState);
Each step state, KernelProcessStepStateMetadata, has a public object? State {...}
property to store the internal state of the step, but control over how this state is deserialized when rebuilding a process is not really provided...
Prior state is passed through ProcessBuilder.Build -> BuildWithStateMetadata -> BuildStep which internally calls:
this._initialState = jsonState.Deserialize(userStateType);
If the user has read in a prior state from some database which uses non default JsonSerializerOptions, converting this state object back to strong type becomes a bit tricky... this is an issue im having when reading some state back in from Cosmos and passing the state to builder.Build
my Cosmos client json settings look roughly like this:
JsonSerializerOptions jsonSerializerOptions = new()
{
PropertyNameCaseInsensitive = true,
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
Converters = { new JsonStringEnumConverter() },
}
so any state object read back from Cosmos is hard to pass back to a new instance of the process b/c the Deserialize call doesn't have the same json options passed in... there are some workarounds depending on prop type (JsonPropertyNameAttibute applied to each state property in the class, other attributes, etc.) but applying sttributes, type converters, and all at a per prop level for every class serialized as part of the state is a bit tedious and easy to forget
Proposed addition:
allow the caller to provide non default JsonSerializerOptions to ProcessBuilder.Build() to override defaults if they want, maybe piping the options though, or allowing a property to be set on the builder - something to support matching the options to the same options configuration used by a database which might store states
maybe something like:
ProcessBuilder.Build(KernelProcessStateMetadata? stateMetadata = null, JsonSerializerOptions? serializerOptions = null) {...}
which internally would use:
this._initialState = jsonState.Deserialize(userStateType, serializerOptions);
this would help me alot to keep everyhting consistent between states stored in Cosmos and expected formats for resuming a process, without spinkinling tons of attributes all thoughout classes that need to be deserialized
Metadata
Metadata
Assignees
Type
Projects
Status