DTO deserialization error on LocalDate fields

HI all,

this topic seems to have been largely discussed, but I’m still struggling to find a solution in my case.

I’m using Camunda 7.15 within JBoss EAP 7.4.
I’m creating an ObjectValue and setting it to the variables passed at the process start like this:

ObjectValue ov = Variables.objectValue(input, transientVariable).serializationDataFormat(Variables.SerializationDataFormats.JAVA).create();
variables.put(ProcessVariableNames.INPUT_PARAMETER.getVariableName(), ov);

Input is my DTO which implements the Serializable interface and includes a Java8 LocalDate field

All seems fine until I try to deserialize the DTO through the Cockpit with deserialization breaking at the LocalDate field:

I learned from this forum that this can be solved adding the SPIN plugin and it’s also highly advised to change the serialization data format from JAVA to JSON.

I applied these 2 changes and the SPIN plugin seems to be detected successfully:

but then when I start my Camunda process I get the following error:

Cannot serialize object in variable 'application': SPIN/JACKSON-JSON-01009 Unable to map object '<skip_this>DTO@fd4a27fc' to json node:

and a bit below in the trace stack:

Caused by: com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Java 8 date/time type `java.time.LocalDate` not supported by default: add Module "com.fasterxml.jackson.datatype:jackson-datatype-jsr310" to enable handling (through reference chain: <skip_this>DTO["applicationDate"])

This in turn seems to be due to the missing jackson-dtatype-jsr310, which I’ve make sure it’s included both in the JBoss modules:

module.xml:

and also included in my app through Maven and I can see it in my external libs:
Screenshot from 2023-10-09 10-28-25

Any idea what could be wrong here?

Thanks!

Hi @ciccio ,

we had similar issues in the past, we also use the SPIN-Plugin.

To solve it we replaced the dependencies on camunda-spin-dataformat-all as follows

<dependency>
    <groupId>org.camunda.spin</groupId>
    <artifactId>camunda-spin-dataformat-all</artifactId>
</dependency>

with the following

<dependency>
    <groupId>org.camunda.spin</groupId>
    <artifactId>camunda-spin-dataformat-json-jackson</artifactId>
</dependency>
<dependency>
    <groupId>com.fasterxml.jackson.datatype</groupId>
    <artifactId>jackson-datatype-jdk8</artifactId>
</dependency>

(The reason behind it is some copying of some classes to a spinjar directory, which messed up our classpath.)

Then we implemented org.camunda.spin.spi.DataFormatConfigurer`. As we use SpringBoot this looks as follows:

@Component
public class CamundaJacksonFormatConfigurator implements DataFormatConfigurator<JacksonJsonDataFormat> {

    @Override
    public Class<JacksonJsonDataFormat> getDataFormatClass() {
        return JacksonJsonDataFormat.class;
    }

    @Override
    public void configure(JacksonJsonDataFormat dataFormat) {
        final ObjectMapper objectMapper = dataFormat.getObjectMapper();
        final JavaTimeModule javaTimeModule = new JavaTimeModule();
        objectMapper.registerModule(javaTimeModule);
    }
}

I am not a 100% sure, if that is valid for current versions, possibly by now it works out of the box, but we still have this code in production with Camunda 7.16.

I hope this helps
Adagatiya

Thank you @Adagatiya .

I tried that but then ended up in a dependency hell and after spending some time we realized that Camunda 7.20 supports Java8 Time types out of the box, so we are just upgrading version.
Thanks.

1 Like

Hi @ciccio ,

good to know, thank you for pointing out!
So one more extra piece of code we can rid off, when upgrading.

Kind regards
Adagatiya

Hi, Folks!

I only saw this topic now…

Did your DTO have an empty constructor @ciccio ? Because deserialization errors can occur due to the lack of an empty constructor, since Jackson uses reflection when doing this.

William Robert Alves