11package com.caplin.integration.datasourcex.util
22
33import com.caplin.datasource.DataSource
4+ import com.caplin.datasource.messaging.json.JacksonJsonHandler
5+ import com.fasterxml.jackson.databind.ObjectMapper
6+ import com.fasterxml.jackson.databind.SerializationFeature.WRITE_DATES_AS_TIMESTAMPS
7+ import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule
8+ import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
49import java.nio.file.Files
510import java.util.logging.Logger
611
@@ -10,20 +15,29 @@ object SimpleDatasourceFactory {
1015
1116 private val logger = getLogger<SimpleDatasourceFactory >()
1217
18+ val defaultObjectMapper: ObjectMapper =
19+ jacksonObjectMapper()
20+ .configure(WRITE_DATES_AS_TIMESTAMPS , false )
21+ .registerModule(JavaTimeModule ())
22+
1323 /* *
1424 * Creates a data source based on the given simple configuration.
1525 *
1626 * @param simpleConfig The simple configuration for the data source.
1727 * @return The created data source.
1828 */
1929 @JvmStatic
20- fun createDataSource (simpleConfig : SimpleDataSourceConfig ): DataSource {
30+ fun createDataSource (
31+ simpleConfig : SimpleDataSourceConfig ,
32+ objectMapper : ObjectMapper = defaultObjectMapper
33+ ): DataSource {
2134 val logPath =
2235 simpleConfig.logDirectory
2336 ? : run {
2437 val tmpLogPath =
2538 Files .createTempDirectory(
26- simpleConfig.name.replace(" \\ s" .toRegex(), " " ).take(MAX_PATH_LENGTH ))
39+ simpleConfig.name.replace(" \\ s" .toRegex(), " " ).take(MAX_PATH_LENGTH ),
40+ )
2741 logger.warn {
2842 " log file path is not specified, writing datasource logs to $tmpLogPath "
2943 }
@@ -50,24 +64,24 @@ object SimpleDatasourceFactory {
5064 |datasrc-dev-override ${simpleConfig.devOverride}
5165 |discovery-require-service ${simpleConfig.requiredServices.joinToString(" " )}
5266 ${
53- simpleConfig.incoming?.let {
54- """
67+ simpleConfig.incoming?.let {
68+ """
5569 |${if (it.isWebsocket) " datasrc-ws-port" else " datasrc-port" } ${it.port}
5670 """
57- }.orEmpty()
58- }
71+ }.orEmpty()
72+ }
5973 ${
60- simpleConfig.outgoing.joinToString(" \n " ) {
61- """
74+ simpleConfig.outgoing.joinToString(" \n " ) {
75+ """
6276 |add-peer
6377 | addr ${it.hostname}
6478 | port ${it.port}
6579 | local-type active|contrib
6680 | websocket ${it.isWebsocket}
6781 |end-peer
6882 """
69- }
70- }
83+ }
84+ }
7185 """
7286 }
7387
@@ -99,5 +113,12 @@ object SimpleDatasourceFactory {
99113 .trimMargin()
100114
101115 return DataSource .fromConfigString(config, Logger .getLogger(DataSource ::class .qualifiedName))
116+ .apply {
117+ extraConfiguration.jsonHandler =
118+ JacksonJsonHandler (
119+ Logger .getLogger(JacksonJsonHandler ::class .qualifiedName),
120+ objectMapper,
121+ )
122+ }
102123 }
103124}
0 commit comments