|
1 | 1 | package io.camunda.zeebe.spring.client;
|
2 | 2 |
|
| 3 | +import static com.fasterxml.jackson.databind.DeserializationFeature.ACCEPT_EMPTY_ARRAY_AS_NULL_OBJECT; |
| 4 | +import static com.fasterxml.jackson.databind.DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES; |
| 5 | + |
3 | 6 | import com.fasterxml.jackson.databind.ObjectMapper;
|
| 7 | +import io.camunda.common.json.SdkObjectMapper; |
4 | 8 | import io.camunda.zeebe.client.ZeebeClient;
|
5 | 9 | import io.camunda.zeebe.client.api.JsonMapper;
|
6 | 10 | import io.camunda.zeebe.client.impl.ZeebeObjectMapper;
|
7 | 11 | import io.camunda.zeebe.spring.client.configuration.*;
|
8 | 12 | import io.camunda.zeebe.spring.client.event.ZeebeLifecycleEventProducer;
|
9 | 13 | import io.camunda.zeebe.spring.client.testsupport.SpringZeebeTestContext;
|
| 14 | +import java.lang.invoke.MethodHandles; |
10 | 15 | import org.slf4j.Logger;
|
11 | 16 | import org.slf4j.LoggerFactory;
|
12 | 17 | import org.springframework.boot.autoconfigure.AutoConfigureAfter;
|
|
17 | 22 | import org.springframework.context.annotation.Bean;
|
18 | 23 | import org.springframework.context.annotation.Configuration;
|
19 | 24 |
|
20 |
| -import java.lang.invoke.MethodHandles; |
21 |
| - |
22 |
| -import static com.fasterxml.jackson.databind.DeserializationFeature.ACCEPT_EMPTY_ARRAY_AS_NULL_OBJECT; |
23 |
| -import static com.fasterxml.jackson.databind.DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES; |
24 |
| - |
25 |
| -/** |
26 |
| - * |
27 |
| - * Enabled by META-INF of Spring Boot Starter to provide beans for Camunda Clients |
28 |
| - */ |
| 25 | +/** Enabled by META-INF of Spring Boot Starter to provide beans for Camunda Clients */ |
29 | 26 | @Configuration
|
30 | 27 | @ImportAutoConfiguration({
|
31 | 28 | ZeebeClientProdAutoConfiguration.class,
|
|
35 | 32 | ZeebeActuatorConfiguration.class,
|
36 | 33 | MetricsDefaultConfiguration.class
|
37 | 34 | })
|
38 |
| -@AutoConfigureAfter(JacksonAutoConfiguration.class) // make sure Spring created ObjectMapper is preferred if available |
| 35 | +@AutoConfigureAfter( |
| 36 | + JacksonAutoConfiguration |
| 37 | + .class) // make sure Spring created ObjectMapper is preferred if available |
39 | 38 | public class CamundaAutoConfiguration {
|
40 | 39 |
|
| 40 | + public static final ObjectMapper DEFAULT_OBJECT_MAPPER = |
| 41 | + new ObjectMapper() |
| 42 | + .configure(FAIL_ON_UNKNOWN_PROPERTIES, false) |
| 43 | + .configure(ACCEPT_EMPTY_ARRAY_AS_NULL_OBJECT, true); |
41 | 44 | private static final Logger LOG = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
|
42 | 45 |
|
43 |
| - public static final ObjectMapper DEFAULT_OBJECT_MAPPER = new ObjectMapper() |
44 |
| - .configure(FAIL_ON_UNKNOWN_PROPERTIES, false) |
45 |
| - .configure(ACCEPT_EMPTY_ARRAY_AS_NULL_OBJECT, true); |
46 |
| - |
47 | 46 | @Bean
|
48 |
| - @ConditionalOnMissingBean(SpringZeebeTestContext.class) // only run if we are not running in a test case - as otherwise the the lifecycle is controlled by the test |
49 |
| - public ZeebeLifecycleEventProducer zeebeLifecycleEventProducer(final ZeebeClient client, final ApplicationEventPublisher publisher) { |
| 47 | + @ConditionalOnMissingBean( |
| 48 | + SpringZeebeTestContext |
| 49 | + .class) // only run if we are not running in a test case - as otherwise the the lifecycle |
| 50 | + // is controlled by the test |
| 51 | + public ZeebeLifecycleEventProducer zeebeLifecycleEventProducer( |
| 52 | + final ZeebeClient client, final ApplicationEventPublisher publisher) { |
50 | 53 | return new ZeebeLifecycleEventProducer(client, publisher);
|
51 | 54 | }
|
52 | 55 |
|
53 | 56 | /**
|
54 |
| - * Registering a JsonMapper bean when there is none already exists in {@link org.springframework.beans.factory.BeanFactory}. |
| 57 | + * Registering a JsonMapper bean when there is none already exists in {@link |
| 58 | + * org.springframework.beans.factory.BeanFactory}. |
55 | 59 | *
|
56 |
| - * NOTE: This method SHOULD NOT be explicitly called as it might lead to unexpected behaviour due to the |
57 |
| - * {@link ConditionalOnMissingBean} annotation. i.e. Calling this method when another JsonMapper bean is defined in the context |
58 |
| - * might throw {@link org.springframework.beans.factory.NoSuchBeanDefinitionException} |
| 60 | + * <p>NOTE: This method SHOULD NOT be explicitly called as it might lead to unexpected behaviour |
| 61 | + * due to the {@link ConditionalOnMissingBean} annotation. i.e. Calling this method when another |
| 62 | + * JsonMapper bean is defined in the context might throw {@link |
| 63 | + * org.springframework.beans.factory.NoSuchBeanDefinitionException} |
59 | 64 | *
|
60 |
| - * @return a new JsonMapper bean if none already exists in {@link org.springframework.beans.factory.BeanFactory} |
| 65 | + * @return a new JsonMapper bean if none already exists in {@link |
| 66 | + * org.springframework.beans.factory.BeanFactory} |
61 | 67 | */
|
62 | 68 | @Bean(name = "zeebeJsonMapper")
|
63 | 69 | @ConditionalOnMissingBean
|
64 | 70 | public JsonMapper jsonMapper(ObjectMapper objectMapper) {
|
65 | 71 | return new ZeebeObjectMapper(objectMapper);
|
66 | 72 | }
|
67 | 73 |
|
| 74 | + |
| 75 | + @Bean(name = "commonJsonMapper") |
| 76 | + @ConditionalOnMissingBean |
| 77 | + public io.camunda.common.json.JsonMapper commonJsonMapper(ObjectMapper objectMapper) { |
| 78 | + return new SdkObjectMapper(objectMapper); |
| 79 | + } |
68 | 80 | }
|
0 commit comments