Cannot be cast to org.camunda.spin.plugin.variable.value.JsonValue

Process Started with the following Input as Json.

{“variables”:{“customerData”:{“value”:“{"myDecision":"filevalidated"}”,“type”:“Json”}}}

Java Delegate

import org.camunda.spin.plugin.variable.value.JsonValue;
import org.camunda.spin.plugin.variable.value.impl.JsonValueImpl;
import org.camunda.spin.impl.json.jackson.JacksonJsonNode;
import static org.camunda.spin.Spin.*;

public class GetDetailsDelegate implements JavaDelegate {
	public void execute(DelegateExecution execution) throws Exception {
		
		JsonValue customer2 = execution.getVariableTyped("customerData");*
		System.out.println("GetDetailsDelegate---customer2---:"+customer2);
	}

}

When I am printing customer details as jsonvalue, I am getting following error.

java.lang.ClassCastException: org.camunda.spin.plugin.variable.value.impl.JsonValueImpl cannot be cast to org.camunda.spin.plugin.variable.value.JsonValue

Hi @somehanu,

can you please provide more information about your environment and the Camunda version.
Do you use a shared process engine?
What application server do you use?
Can you provide a failing test?

Maybe, it’s a problem with the class loading. Please check that library is loaded only once.

Best regards,
Philipp

Issue get solved by using the spin fasterxml object mapper as following. Because camunda treating json request as object

Imported Libraries;

import spinjar.com.fasterxml.jackson.core.JsonParseException;
import spinjar.com.fasterxml.jackson.databind.JsonMappingException;
import spinjar.com.fasterxml.jackson.databind.ObjectMapper;

Example Code:

Object customer = execution.getVariableTyped("customerData").getValue(); 
String customerValues = customer.toString();
ObjectMapper mapper = new ObjectMapper();
LoanDetail customers = mapper.readValue(customerValues, CustomerData.class);
1 Like

Hi.
I preffer add aditional rest endpoint.
You need add 2 files to project:

  1. JerseyConfig -
    @Component
    @ApplicationPath("/rest")
    public class JerseyConfig extends CamundaJerseyResourceConfig {

    @Override
    protected void registerAdditionalResources() {
    register(TaskFieldsService.class);
    }

  2. TaskFieldsService:

@Path("/taskfields")
public class TaskFieldsService {

@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("{taskId}")
public String getFormFieldList(@Context HttpHeaders httpHeaders, @PathParam("taskId") String taskId ){


        ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
        FormService formService = processEngine.getFormService();
        TaskFormData taskFormData = formService.getTaskFormData(taskId);
        List<FormField> formFieldList = taskFormData.getFormFields();
        System.out.println("Strike");
        String json = JSON(formFieldList).toString();
        return json;





};

}

So you can get form atributes by GET /taskfields/905