Search in sources :

Example 1 with KotlinModule

use of com.fasterxml.jackson.module.kotlin.KotlinModule in project kork by spinnaker.

the class Front50PluginsConfiguration method pluginFront50Service.

@Bean
public static Front50Service pluginFront50Service(Environment environment, PluginOkHttpClientProvider pluginsOkHttpClientProvider, Map<String, PluginRepositoryProperties> pluginRepositoriesConfig) {
    PluginRepositoryProperties front50RepositoryProps = pluginRepositoriesConfig.get(PluginsConfigurationProperties.FRONT5O_REPOSITORY);
    URL front50Url = getFront50Url(environment, front50RepositoryProps);
    KotlinModule kotlinModule = new KotlinModule.Builder().build();
    ObjectMapper objectMapper = new ObjectMapper().registerModule(kotlinModule).configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false).configure(SerializationFeature.INDENT_OUTPUT, true).setSerializationInclusion(JsonInclude.Include.NON_NULL);
    return new Retrofit.Builder().addConverterFactory(JacksonConverterFactory.create(objectMapper)).baseUrl(front50Url).client(pluginsOkHttpClientProvider.getOkHttpClient()).build().create(Front50Service.class);
}
Also used : Retrofit(retrofit2.Retrofit) PluginRepositoryProperties(com.netflix.spinnaker.config.PluginsConfigurationProperties.PluginRepositoryProperties) KotlinModule(com.fasterxml.jackson.module.kotlin.KotlinModule) URL(java.net.URL) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Bean(org.springframework.context.annotation.Bean)

Example 2 with KotlinModule

use of com.fasterxml.jackson.module.kotlin.KotlinModule in project ontrack by nemerosa.

the class ObjectMapperFactory method create.

public static ObjectMapper create() {
    ObjectMapper mapper = new ObjectMapper();
    // Support for JDK 8 times
    jdkTime(mapper);
    // Support for Kotlin
    mapper.registerModule(new KotlinModule());
    // OK
    return mapper;
}
Also used : KotlinModule(com.fasterxml.jackson.module.kotlin.KotlinModule) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 3 with KotlinModule

use of com.fasterxml.jackson.module.kotlin.KotlinModule in project kork by spinnaker.

the class HttpClientSdkConfiguration method httpClientSdkFactory.

@Bean
public static SdkFactory httpClientSdkFactory(List<OkHttp3ClientFactory> okHttpClientFactories, Environment environment, Provider<Registry> registry) {
    OkHttpClientConfigurationProperties okHttpClientProperties = Binder.get(environment).bind("ok-http-client", Bindable.of(OkHttpClientConfigurationProperties.class)).orElse(new OkHttpClientConfigurationProperties());
    OkHttpMetricsInterceptorProperties okHttpMetricsInterceptorProperties = Binder.get(environment).bind("ok-http-client.interceptor", Bindable.of(OkHttpMetricsInterceptorProperties.class)).orElse(new OkHttpMetricsInterceptorProperties());
    List<OkHttp3ClientFactory> factories = new ArrayList<>(okHttpClientFactories);
    OkHttp3MetricsInterceptor okHttp3MetricsInterceptor = new OkHttp3MetricsInterceptor(registry, okHttpMetricsInterceptorProperties);
    factories.add(new DefaultOkHttp3ClientFactory(okHttp3MetricsInterceptor));
    OkHttp3ClientConfiguration config = new OkHttp3ClientConfiguration(okHttpClientProperties, okHttp3MetricsInterceptor);
    KotlinModule kotlinModule = new KotlinModule.Builder().build();
    // TODO(rz): It'd be nice to make this customizable, but I'm not sure how to do that without
    // bringing Jackson into the Plugin SDK (quite undesirable).
    ObjectMapper objectMapper = new ObjectMapper();
    objectMapper.registerModule(new Jdk8Module());
    objectMapper.registerModule(new JavaTimeModule());
    objectMapper.registerModule(kotlinModule);
    objectMapper.disable(READ_DATE_TIMESTAMPS_AS_NANOSECONDS);
    objectMapper.disable(WRITE_DATE_TIMESTAMPS_AS_NANOSECONDS);
    objectMapper.disable(FAIL_ON_UNKNOWN_PROPERTIES);
    objectMapper.disable(FAIL_ON_EMPTY_BEANS);
    objectMapper.setSerializationInclusion(NON_NULL);
    return new HttpClientSdkFactory(new CompositeOkHttpClientFactory(factories), environment, objectMapper, config);
}
Also used : CompositeOkHttpClientFactory(com.netflix.spinnaker.kork.plugins.sdk.httpclient.internal.CompositeOkHttpClientFactory) JavaTimeModule(com.fasterxml.jackson.datatype.jsr310.JavaTimeModule) ArrayList(java.util.ArrayList) HttpClientSdkFactory(com.netflix.spinnaker.kork.plugins.sdk.httpclient.HttpClientSdkFactory) Jdk8Module(com.fasterxml.jackson.datatype.jdk8.Jdk8Module) OkHttp3MetricsInterceptor(com.netflix.spinnaker.okhttp.OkHttp3MetricsInterceptor) OkHttp3ClientFactory(com.netflix.spinnaker.kork.plugins.sdk.httpclient.OkHttp3ClientFactory) DefaultOkHttp3ClientFactory(com.netflix.spinnaker.kork.plugins.sdk.httpclient.internal.DefaultOkHttp3ClientFactory) DefaultOkHttp3ClientFactory(com.netflix.spinnaker.kork.plugins.sdk.httpclient.internal.DefaultOkHttp3ClientFactory) KotlinModule(com.fasterxml.jackson.module.kotlin.KotlinModule) OkHttpClientConfigurationProperties(com.netflix.spinnaker.okhttp.OkHttpClientConfigurationProperties) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Bean(org.springframework.context.annotation.Bean)

Aggregations

ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 KotlinModule (com.fasterxml.jackson.module.kotlin.KotlinModule)3 Bean (org.springframework.context.annotation.Bean)2 Jdk8Module (com.fasterxml.jackson.datatype.jdk8.Jdk8Module)1 JavaTimeModule (com.fasterxml.jackson.datatype.jsr310.JavaTimeModule)1 PluginRepositoryProperties (com.netflix.spinnaker.config.PluginsConfigurationProperties.PluginRepositoryProperties)1 HttpClientSdkFactory (com.netflix.spinnaker.kork.plugins.sdk.httpclient.HttpClientSdkFactory)1 OkHttp3ClientFactory (com.netflix.spinnaker.kork.plugins.sdk.httpclient.OkHttp3ClientFactory)1 CompositeOkHttpClientFactory (com.netflix.spinnaker.kork.plugins.sdk.httpclient.internal.CompositeOkHttpClientFactory)1 DefaultOkHttp3ClientFactory (com.netflix.spinnaker.kork.plugins.sdk.httpclient.internal.DefaultOkHttp3ClientFactory)1 OkHttp3MetricsInterceptor (com.netflix.spinnaker.okhttp.OkHttp3MetricsInterceptor)1 OkHttpClientConfigurationProperties (com.netflix.spinnaker.okhttp.OkHttpClientConfigurationProperties)1 URL (java.net.URL)1 ArrayList (java.util.ArrayList)1 Retrofit (retrofit2.Retrofit)1