Variable saved as LinkedHashMap

We have a process that normally works as expected, but only when we have a huge load of process instances we see many incidents of this error:
java.lang.ClassCastException: java.util.LinkedHashMap cannot be cast to …

This error happens because a variable, wich should be of a class type of ours, was saved as LinkedHashmap and we dont know why. So when another delegate tries to do a getVariable and cast it to our type it gives me this class cast exception.

Theres nothing fancy about how we save this variable, this is just:
variableScope.setVariable( “myVariableName”, myObject);

And the code that gives the classCastException is:
return (MyType) variableScope.getVariable(“myVariableName”);

Its weird because we have this process running 24/7, working normally, but only in times of huge load some instances save this as a linkedhashmap instead of the correct type.

I need to execute this update in database and then start a job retry by rest api to solve it everytime:

update ACT_RU_VARIABLE 
set TEXT2_ = "com.company.MyType"  
where NAME_ like "myVariableName"  
AND TEXT2_ = "java.util.LinkedHashMap<java.lang.Object,java.lang.Object>";

We are using camunda springboot 7.13.0 with mysql 5.7 database in a clustered environment with multiple pods running this project.
We also have this dependencies in our build.gradle that maybe are related to this type serialization problem:

compile(“org.camunda.bpm:camunda-engine-plugin-spin:7.13.0”)
compile(“org.camunda.spin:camunda-spin-core:1.10.1”)
compile(“org.camunda.spin:camunda-spin-dataformat-json-jackson:1.10.1”)

its happening again in a camunda 7.19 project. Some variables started to be saved as linkedHashMap again instead of our custom java type
IMG-20230720-WA0004

Hi @Jean_Robert_Alves

Did you try to use getVriableTyped method instead of getVariable?

TypedValue myObjectTypedValue = execution.getVariableTyped("myObject");
MyCustomObject myCustomObject = (MyCustomObject) myObjectTypedValue.getValue();

Today i was just using it in an expression, calling a method from the object but got this error because it was suddenly saved as linkedhashmap.
I always used setVariable to save java objects and always saved the type correctly, just in this two scenarios i got it saved wrong and I dont know why