How to configure connector to use serialized object as request body in json format in post request

I have set default-serialization-format: application/json.
Inside java code I am building a request object and passing it as variable to camunda process. I have a service task where I have configured http-connector to call external rest service. I am not able to pass the saved java object as json body in post request.

Request request = new Request();
ProcessInstanceWithVariables processVariableInReturn
 =processEngine.getRuntimeService()
.createProcessInstanceByKey(PROCESS_DEFINITION_KEY)
.setVariable("request", request)
.executeWithVariablesInReturn();

I got ClassCastException:

java.lang.ClassCastException: org.camunda.spin.impl.json.jackson.JacksonJsonNode cannot be cast to java.lang.String

Connector config for post call:

You need to convert your payload into a JSON string. JSON.Stringify(...)

I have added JSON.stringify(...)

var obj = execution.getVariableTyped("request");
JSON.stringify(obj.getValueSerialized()); 

Again same exception: java.lang.ClassCastException: org.camunda.spin.impl.json.jackson.JacksonJsonNode cannot be cast to java.lang.String

I believe obj.getValueSerialized() is not even evaluated. Method getValueSeralized() may not be available in script context.

You stringify the Spin variable. JSON.stringify(S(…))

Getting the same exception.

Is there any document on configuring the http-connector in detail? There are some examples on git but they are very basic examples.

Try this.

List names = new ArrayList();
names.add(“Johann Cruyff”);
names.add(“Franz Beckenbauer”);
names.add(“Gerd Muller”);

	ObjectValue batchesDataValue = Variables.objectValue(names)
            .serializationDataFormat(Variables.SerializationDataFormats.JSON)
            .create();
	
	execution.setVariable("AVAILABLE_NAMES",   batchesDataValue);

@Kamalakar_Kale what is your Request object? Do you have a Jackson mapper assignment for a JsonCreator?

Camunda and Camunda SPIN S() uses Jackson.

So here is a example:

Where the “UserDocument” is using:

The S() is just a helper to use instead of a custom mapping.

What you want to read about is how camunda does serialization https://docs.camunda.org/manual/7.10/user-guide/data-formats/data-formats-in-processes/.

HttpConnector is just a wrapper around Apache HTTP Client. the payload field is just a String value which is JSON string.

I don’t have any problem in serializing a variable.
I have set the default serialization format to application/json. I can see that variable is saved in the h2 database in ACT_GE_BYTEARRAY table. The problem is when I try to read the same variable inside http-connector configuration, I am not able to convert it to string. Variable that I am getting in connector config is of type JacksonJsonNode node and not a java object type that I have used to create initially.
May be while creating a payload via script , I have used a wrong API to get variable value from execution context.