External Task Client set json process variable

Hello guys,

I’m trying to set a json process variable through the external task client.
According to the docs I have to create a JsonValue Object:

JsonValue jsonValue = SpinValues.jsonValue(jsonString).create();
externalTaskService.complete(externalTask, Collections.singletonMap("order", jsonValue));

above code results in following error:

org.camunda.bpm.client.exception.ValueMapperException: TASK/CLIENT-01025 Cannot serialize variable 'order'
	at org.camunda.bpm.client.impl.ExternalTaskClientLogger.cannotSerializeVariable(ExternalTaskClientLogger.java:199)
	at org.camunda.bpm.client.variable.impl.TypedValues.serializeVariables(TypedValues.java:60)
	at org.camunda.bpm.client.impl.EngineClient.complete(EngineClient.java:83)
	at org.camunda.bpm.client.task.impl.ExternalTaskServiceImpl.complete(ExternalTaskServiceImpl.java:62)
	at org.camunda.bpm.client.task.impl.ExternalTaskServiceImpl.complete(ExternalTaskServiceImpl.java:56)
	at de.netcombw.orderspring.adapter.CreateContractGdata.lambda$init$0(CreateContractGdata.java:73)
	at org.camunda.bpm.client.topic.impl.TopicSubscriptionManager.handleExternalTask(TopicSubscriptionManager.java:152)
	at org.camunda.bpm.client.topic.impl.TopicSubscriptionManager.lambda$acquire$0(TopicSubscriptionManager.java:108)
	at java.base/java.util.Arrays$ArrayList.forEach(Arrays.java:4390)
	at org.camunda.bpm.client.topic.impl.TopicSubscriptionManager.acquire(TopicSubscriptionManager.java:103)
	at org.camunda.bpm.client.topic.impl.TopicSubscriptionManager.run(TopicSubscriptionManager.java:87)
	at java.base/java.lang.Thread.run(Thread.java:834)
Caused by: org.camunda.bpm.client.exception.ValueMapperException: TASK/CLIENT-01023 Cannot find serializer for value 'Value 'null' of type 'json', isTransient=false'
	at org.camunda.bpm.client.impl.ExternalTaskClientLogger.valueMapperExceptionDueToSerializerNotFoundForTypedValue(ExternalTaskClientLogger.java:189)
	at org.camunda.bpm.client.variable.impl.DefaultValueMappers.findMapperForTypedValue(DefaultValueMappers.java:70)
	at org.camunda.bpm.client.variable.impl.TypedValues.findSerializer(TypedValues.java:114)
	at org.camunda.bpm.client.variable.impl.TypedValues.toTypedValueField(TypedValues.java:92)
	at org.camunda.bpm.client.variable.impl.TypedValues.serializeVariables(TypedValues.java:56)
	... 10 more
2 Likes

The external task client uses a value mapper for json which supports the class
org.camunda.bpm.client.variable.impl.type.JsonTypeImpl

This can be created without SPIN dependencies on the external client by using:

import org.camunda.bpm.client.variable.ClientValues;
import org.camunda.bpm.client.variable.value.JsonValue;

JsonValue jsonValue = ClientValues.jsonValue(responseBody);

I don’t see the import in the code snippet, but guess you are using the standard SPIN approach for JavaDelegates, which creates:
*org.camunda.**spin.plugin.*variable.type.impl.JsonValueTypeImpl

Also see: External Task Client | docs.camunda.org

1 Like