Skip to content
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

Serializing complex objects from Camunda.Api.Client and accessing them in workers #80

Open
akrsmv opened this issue Mar 30, 2021 · 0 comments

Comments

@akrsmv
Copy link

akrsmv commented Mar 30, 2021

Hello, I have an asp netcore 3.1 application that connects to the vanilla docker camunda image. We are solely using external workers that are implemented with the Camunda.Worker library.

I want to pass complex object to a running instance, form my aspnet api project, however whatever I tried I am getting the error:

Type Object not in [Json]

the code I am using for starting a process instance with complex variables:

pseudo code:

           public class ComplObject {
                public string prop1 {get; set;}
           }
            var myObjectVariable = new ComplObject { prop1 = "abc"} 

            var processParams = new StartProcessInstance
            {
                BusinessKey = "my business key",
                SkipIoMappings = false,
                Variables = new Dictionary<string, VariableValue>
                 {
                     "myComplexObject", VariableValue.FromObject(myObjectVariable )
                 }
            };

            Camunda.ProcessDefinitions[someId].StartProcessInstance(processParams);

Later when I try to obtain the variable from a worker, I am getting the above-mentioned error Type Object not in [Json]

I saw lots of tests in Camunda.Worker project and being only in the context of Camunda.Worker I have no problems using the methods like .AsJson .AsString.

I think there is something around Camunda.Api.Client.VariableValue and Camunda.Worker.Variable classes that I am missing.

the only workaround so far for me is to pass an instance of Camunda.Worker.Variable to the Camunda.Api.Client.VariableValue.FromObject method, explicitly stating the ValueType.Json. However later on, when I want to obtain the typed variables from a worker, I need to do this extra hacky code:

JsonConvert.DeserializeObject<Variable>(camundaVariable.Value.ToString()).AsJson<T>();

I wonder what am I doing wrong.

Please advice

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant