JsonMappingException with Camunda

I have an object with a java.time.LocalDateTime member variable. This object is serialized and deserialized as part of my Camunda process.

But when I run the process, I get a JsonMappingException:

    Caused by: spinjar.com.fasterxml.jackson.databind.JsonMappingException: No suitable constructor found for type [simple type, class java.time.LocalDateTime]: can not instantiate from JSON object (missing default constructor or creator, or perhaps need to add/enable type information?)
     at [Source: N/A; line: -1, column: -1] (through reference chain: my.package.MyObject["myVar"]->myVar["changedDateTime"])
    at spinjar.com.fasterxml.jackson.databind.JsonMappingException.from(JsonMappingException.java:148)

I have gotten around this in other cases (without Camunda) by adding the jackson-datatype-jsr310 dependency and doing the following:

ObjectMapper mapper = new ObjectMapper();
mapper.registerModule(new JavaTimeModule());
mapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);

However with spinjar it seems like the spinjar ObjectMapper cannot register the JavaTimeModule.

I found this link that mentioned dataformatting https://github.com/camunda/camunda-bpm-examples/tree/master/spin/dataformat-configuration-global but it seems like doing a lot of work for something that should be pretty simple.

Does anyone have any solutions for this? It feels yucky to change my LocalDateTime variable to a String just to keep Camunda happy :frowning:

2 Likes

Were you able to resolve this? I am also running into same issue where its not accepting JavaTimeModule because of Camunda putting jackson classes into spin.* package

mapper.registerModule(new JavaTimeModule());

Unfortunately not. I used String as the type for my date variable.
The workaround specified in the link seemed like too much trouble for something that should have been quite simple.

I’m afraid this is the way to go with a shared engine on Tomcat. Thanks to Tomcat’s single shared classloader, the Camunda distribution for Tomcat must relocate Jackson to avoid polluting the classpath with an arbitrary Jackson version. If you would like to use a Camunda distribution that does not use relocated Jackson libraries, check out the Wildfly distribution. Wildfly has a proper module system :slight_smile:

1 Like