diff --git a/spring-boot-starter-camunda/src/main/java/io/camunda/zeebe/spring/client/configuration/JsonMapperConfiguration.java b/spring-boot-starter-camunda/src/main/java/io/camunda/zeebe/spring/client/configuration/JsonMapperConfiguration.java index c7b853ec7..b6e0a0a0d 100644 --- a/spring-boot-starter-camunda/src/main/java/io/camunda/zeebe/spring/client/configuration/JsonMapperConfiguration.java +++ b/spring-boot-starter-camunda/src/main/java/io/camunda/zeebe/spring/client/configuration/JsonMapperConfiguration.java @@ -24,7 +24,7 @@ public JsonMapper jsonMapper() { if (objectMapper == null) { return new ZeebeObjectMapper(); } - return new ZeebeObjectMapper(objectMapper); + return new ZeebeObjectMapper(objectMapper.copy()); } @Bean(name = "commonJsonMapper") @@ -33,6 +33,6 @@ public io.camunda.common.json.JsonMapper commonJsonMapper() { if (objectMapper == null) { return new SdkObjectMapper(); } - return new SdkObjectMapper(objectMapper); + return new SdkObjectMapper(objectMapper.copy()); } } diff --git a/spring-boot-starter-camunda/src/test/java/io/camunda/zeebe/spring/client/config/JsonMapperConfigurationTest.java b/spring-boot-starter-camunda/src/test/java/io/camunda/zeebe/spring/client/config/JsonMapperConfigurationTest.java new file mode 100644 index 000000000..0a419157d --- /dev/null +++ b/spring-boot-starter-camunda/src/test/java/io/camunda/zeebe/spring/client/config/JsonMapperConfigurationTest.java @@ -0,0 +1,41 @@ +package io.camunda.zeebe.spring.client.config; + +import static org.assertj.core.api.Assertions.assertThat; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import io.camunda.common.json.JsonMapper; +import io.camunda.zeebe.spring.client.configuration.JsonMapperConfiguration; +import java.util.HashMap; +import java.util.Map; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration; +import org.springframework.boot.test.context.SpringBootTest; + +@SpringBootTest(classes = {JacksonAutoConfiguration.class, JsonMapperConfiguration.class}) +public class JsonMapperConfigurationTest { + + @Autowired private io.camunda.zeebe.client.api.JsonMapper zeebeJsonMapper; + + @Autowired private JsonMapper commonJsonMapper; + + @Test + public void shouldSerializeNullValuesInJson() throws JsonProcessingException { + // given + final Map map = new HashMap<>(); + map.put("key", null); + map.put("key2", "value2"); + // when + final JsonNode zeebeJsonNode = new ObjectMapper().readTree(zeebeJsonMapper.toJson(map)); + final JsonNode commonJsonNode = new ObjectMapper().readTree(commonJsonMapper.toJson(map)); + + // then + assertThat(zeebeJsonNode.get("key")).isNotNull(); + assertThat(commonJsonNode.get("key")).isNull(); + + assertThat(zeebeJsonNode.get("key2").asText()).isEqualTo("value2"); + assertThat(commonJsonNode.get("key2").asText()).isEqualTo("value2"); + } +}