Return Java Object from Process Engine

Hello everyone (I’m new in this forum so please don’t judge me :pray:),
To my question: Is it possible to return Java Objects (or at least Json) from the Process Engine?

I’m doing some testing on processes with Spring Boot Camunda. I need to start a process with a process variable which I set as Java Object. I want to modify this object within a Java Delegate and test afterwards that the changes were done right. I have tried it with HistoricVariableInstance but i just get the name of process variables. I don’t know how to modify this object via DelegateExecution, but HistoricVariableInstance still returns empty values. Can someone help?

@SpringBootTest(classes = ProcessApplication.class)
@TestPropertySource(locations = { "classpath:test.properties" })
public class TestJsonThroughProcessTestNG extends AbstractTestNGSpringContextTests {
    @Autowired
    RuntimeService runtimeService;
    @Autowired
    ProcessEngine processEngine;
    private Record cr;
    @BeforeMethod
    public void setUp() {
        this.mapper = new ObjectMapper();
        cr = new Record();
        cr.setId(Integer.valueOf(1234));
        cr.setFirstName("Max");
        cr.setLastName("Mustermann");
        cr.setComplaintDate(Instant.now());
        cr.setListOfThings(new ArrayList<String>(Arrays.asList("here", "there", "everywhere")));
    }
    @Test
    public void testGetObject() {
        ProcessInstance pi = this.runtimeService.startProcessInstanceByKey("sendResponseTest",
                Variables.createVariables().putValue("Record", cr));
        List<HistoricVariableInstance> variables = this.processEngine.getHistoryService()
                .createHistoricVariableInstanceQuery().processInstanceId(pi.getId()).list();
}

Greetings
Alex

Hi @Haagy,

See https://docs.camunda.org/manual/7.9/user-guide/process-engine/variables/#java-object-api for how to set and access object variables from within a JavaDelegate. In addition, you can access the historic variable value via HistoricVariableInstance#getValue.

Cheers,
Thorben

Good morning @thorben,

I guess it would work, but I’m getting some deserialize errors.

org.camunda.bpm.engine.ProcessEngineException: Cannot deserialize object in variable 'Record': SPIN/JACKSON-JSON-01006 Cannot deserialize '{"id":1234...' to java type '[simple type, class com.example.camunda.pojo.Record]'

Caused by: org.camunda.spin.json.SpinJsonException: SPIN/JACKSON-JSON-01006 Cannot deserialize '{"id":1234...' to java type '[simple type, class com.example.camunda.pojo.Record]'

Caused by: com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Cannot construct instance of `java.time.Instant` (no Creators, like default construct, exist): cannot deserialize from Object value (no delegate- or property-based Creator)
 at [Source: UNKNOWN; line: -1, column: -1] (through reference chain: com.example.camunda.pojo.Record["ComplaintDate"])

Is that because I’m using Instant as datatype for date and the Process Engine can’t parse it?

Greetings,
Alex

I’ve tested it and Instant is the problem. Any suggestions how to do this properly?