-
Notifications
You must be signed in to change notification settings - Fork 121
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #804 from camunda-community-hub/connectors-issues-…
…2648 (#805) bug(object-mapper): Fix our custom mappers creation to avoid mutating the initial ObjectMapper
- Loading branch information
Showing
2 changed files
with
43 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
...unda/src/test/java/io/camunda/zeebe/spring/client/config/JsonMapperConfigurationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<String, Object> 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"); | ||
} | ||
} |