How to use custom data formats with Spin plugin?

Hi folks,

I am using the camunda-spin-plugin to de-/serialize JSON. Now I have a special issue: We are using JavaMoney types in our application and Spin is not able to serialize those correctly.

We are already using jackson for serialization and we use a custom datatype for JavaMoney from Zalando, which is registered as a module for the ObjectMapper:

objectMapper.registerModules(new MoneyModule().withFormatFactory(new DefaultMonetaryAmountFormatFactory()));

But is does not work with Spin out of the box.

I am using Spin in a Gradle built Camunda Spring Boot setup with the following dependencies:

compile 'org.camunda.spin:camunda-spin-core'
compile 'org.camunda.spin:camunda-spin-dataformat-json-jackson'
compile 'org.camunda.bpm:camunda-engine-plugin-spin'

What puzzles me, is that I get an Exception, which points out, that the relocated Jackson artifacts are used, which I would not expect in my setup (since I do not use the -all dependencies):

Caused by: java.lang.NumberFormatException: For input string: "1E+1"
	at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
	at java.lang.Long.parseLong(Long.java:589)
	at java.lang.Long.parseLong(Long.java:631)
	at spinjar.com.fasterxml.jackson.databind.util.TokenBuffer$Parser.getNumberValue(TokenBuffer.java:1476)
	at spinjar.com.fasterxml.jackson.databind.util.TokenBuffer$Parser.getNumberType(TokenBuffer.java:1450)
	at spinjar.com.fasterxml.jackson.databind.deser.std.BaseNodeDeserializer._fromFloat(JsonNodeDeserializer.java:365)
	at spinjar.com.fasterxml.jackson.databind.deser.std.BaseNodeDeserializer.deserializeAny(JsonNodeDeserializer.java:319)
	at spinjar.com.fasterxml.jackson.databind.deser.std.BaseNodeDeserializer.deserializeObject(JsonNodeDeserializer.java:248)
	at spinjar.com.fasterxml.jackson.databind.deser.std.BaseNodeDeserializer.deserializeObject(JsonNodeDeserializer.java:224)
	at spinjar.com.fasterxml.jackson.databind.deser.std.BaseNodeDeserializer.deserializeArray(JsonNodeDeserializer.java:270)
	at spinjar.com.fasterxml.jackson.databind.deser.std.JsonNodeDeserializer.deserialize(JsonNodeDeserializer.java:71)
	at spinjar.com.fasterxml.jackson.databind.deser.std.JsonNodeDeserializer.deserialize(JsonNodeDeserializer.java:15)
	at spinjar.com.fasterxml.jackson.databind.ObjectMapper._readValue(ObjectMapper.java:3708)
	at spinjar.com.fasterxml.jackson.databind.ObjectMapper.readTree(ObjectMapper.java:2113)
	at spinjar.com.fasterxml.jackson.databind.ObjectMapper.valueToTree(ObjectMapper.java:2517)
	at org.camunda.spin.impl.json.jackson.format.JacksonJsonDataFormatMapper.mapJavaToInternal(JacksonJsonDataFormatMapper.java:52)
	... 187 common frames omitted

So I guess I am using a different ObjectMapper than the one, we configure with Spring. Any idea how to get this working with the Spin plugin?

Edit: I found this example, which explains how to configure Spin dataformats. But I still struggle because of the relocated jackson artifacts. How to get rid of those?

Cheers,
Stefan

Answering myself: I eventually got rid of the relocated spinjar jackson artifacts (I think I faced some Gradle cache issue) and I found this in the Camunda examples: https://github.com/camunda/camunda-bpm-examples/tree/master/spin/dataformat-configuration-global.

I wrote my own DataFormatConfigurator to add a module to the Jackson ObjectMapper, which uses the Zalando data format mapper mentioned in my question.

That did the trick!

1 Like