Variable type of date is saved as string

The start task variable of type date is saved as string instead of type date.
processInstance = runtimeService.startProcessInstanceByKey(processKey, variables)
The date variable is in the map variables as string in format "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'". In the BPMN file the date is defined as following:
<camunda:formField id="duedate" label="Due Date" type="date" />.
When I try to get the task variables in the tasks
TaskFormData taskFormData = formService.getTaskFormData(taskId)
where the variable exist, I got this error:
org.camunda.bpm.engine.ProcessEngineException: Expected value to be of type 'PrimitiveValueType[date]' but got 'PrimitiveValueType[string]'.


All the variable values are stored as String Value in the table ACT_HI_VARINST and ACT_RU_VARIABLE. If you query using taskService.createTaskQuery().processDefinitionKey()................list() will return List of Task objects which matches the query filters. The Task object includes date fields which will return you Date Object. If you are using native query to fetch results, then you need to convert it to Date Object

Thank you for your reply.
Do you mean variables are always stored as String in ACT_HI_VARINST and ACT_RU_VARIABLE regardless the type of the variable in the BPMN file?

Yes. Variables are always stored as String in ACT_HI_VARINST and ACT_RU_VARIABLE

If you’re storing a File or Object, it will store as binary data in ACT_GE_PROPERTY.

Ok. Thank you.