diff --git a/README.md b/README.md index b9a6629b0..8929e98a9 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# th2 common library (Java) (5.4.1) +# th2 common library (Java) (5.4.2) ## Usage @@ -494,6 +494,13 @@ dependencies { ## Release notes +### 5.4.2-dev + +#### Fix + ++ The serialization of `LocalTime`, `LocalDate` and `LocalDateTime` instances corrected for th2 transport parsed message. + Old result would look like `[2023,9,7]`. Corrected serialization result looks like `2023-09-07` + ### 5.4.1-dev #### Fix + `SubscriberMonitor` is returned from `MessageRouter.subscribe` methods is proxy object to manage RabbitMQ subscribtion without internal listener diff --git a/gradle.properties b/gradle.properties index 827b6830d..b876306b8 100644 --- a/gradle.properties +++ b/gradle.properties @@ -13,7 +13,7 @@ # See the License for the specific language governing permissions and # limitations under the License. # -release_version=5.4.1 +release_version=5.4.2 description='th2 common library (Java)' vcs_url=https://github.com/th2-net/th2-common-j kapt.include.compile.classpath=false diff --git a/src/main/kotlin/com/exactpro/th2/common/schema/message/impl/rabbitmq/transport/Codecs.kt b/src/main/kotlin/com/exactpro/th2/common/schema/message/impl/rabbitmq/transport/Codecs.kt index 0e43f0c65..5fbd8d8a3 100644 --- a/src/main/kotlin/com/exactpro/th2/common/schema/message/impl/rabbitmq/transport/Codecs.kt +++ b/src/main/kotlin/com/exactpro/th2/common/schema/message/impl/rabbitmq/transport/Codecs.kt @@ -18,6 +18,7 @@ package com.exactpro.th2.common.schema.message.impl.rabbitmq.transport import com.fasterxml.jackson.annotation.JsonInclude import com.fasterxml.jackson.databind.ObjectMapper +import com.fasterxml.jackson.databind.SerializationFeature import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper import com.fasterxml.jackson.module.kotlin.readValue @@ -321,6 +322,9 @@ object ParsedMessageCodec : AbstractCodec(30u) { @JvmField val MAPPER: ObjectMapper = jacksonObjectMapper().registerModule(JavaTimeModule()) + // otherwise, type supported by JavaTimeModule will be serialized as array of date component + .disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS) + // this is required to serialize nulls and empty collections .setSerializationInclusion(JsonInclude.Include.ALWAYS) } diff --git a/src/test/kotlin/com/exactpro/th2/common/schema/message/impl/rabbitmq/transport/CodecsTest.kt b/src/test/kotlin/com/exactpro/th2/common/schema/message/impl/rabbitmq/transport/CodecsTest.kt index f76694250..227ae3f38 100644 --- a/src/test/kotlin/com/exactpro/th2/common/schema/message/impl/rabbitmq/transport/CodecsTest.kt +++ b/src/test/kotlin/com/exactpro/th2/common/schema/message/impl/rabbitmq/transport/CodecsTest.kt @@ -19,8 +19,13 @@ package com.exactpro.th2.common.schema.message.impl.rabbitmq.transport import io.netty.buffer.ByteBufUtil import io.netty.buffer.Unpooled import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.DynamicTest import org.junit.jupiter.api.Test +import org.junit.jupiter.api.TestFactory import java.time.Instant +import java.time.LocalDate +import java.time.LocalDateTime +import java.time.LocalTime class CodecsTest { @@ -121,4 +126,39 @@ class CodecsTest { "unexpected raw body", ) } + + @TestFactory + fun dateTypesTests(): Collection { + val testData = listOf( + LocalDate.now(), + LocalTime.now(), + LocalDateTime.now(), + Instant.now(), + ) + return testData.map { + DynamicTest.dynamicTest("serializes ${it::class.simpleName} as field") { + val parsedMessage = ParsedMessage.builder().apply { + setId(MessageId.DEFAULT) + setType("test") + setBody( + linkedMapOf( + "field" to it, + ) + ) + }.build() + + val dest = Unpooled.buffer() + ParsedMessageCodec.encode(parsedMessage, dest) + val decoded = ParsedMessageCodec.decode(dest) + assertEquals(0, dest.readableBytes()) { "unexpected bytes left: ${ByteBufUtil.hexDump(dest)}" } + + assertEquals(parsedMessage, decoded, "unexpected parsed result decoded") + assertEquals( + "{\"field\":\"$it\"}", + decoded.rawBody.toString(Charsets.UTF_8), + "unexpected raw body", + ) + } + } + } } \ No newline at end of file