Skip to content

Commit 6fcee5f

Browse files
[TH2-5265] fixed: codec can't encode fields with type LocalDateTime, LocalDate, LocalTime and value with timezone (#13)
* Updated sailfish: `3.4.260`
1 parent 187923a commit 6fcee5f

File tree

5 files changed

+54
-6
lines changed

5 files changed

+54
-6
lines changed

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# th2-codec-fix-ng 0.1.1
1+
# th2-codec-fix-ng 0.1.2
22

33
This codec can be used in dirty mode for decoding and encoding messages via the FIX protocol.
44

@@ -47,6 +47,10 @@ Component benchmark results available [here](docs/benchmarks/jmh-benchmark.md).
4747

4848
## Release notes
4949

50+
### 0.1.2
51+
+ fixed: codec can't encode fields with type `LocalDateTime`, `LocalDate`, `LocalTime` and value with timezone
52+
+ Updated sailfish: `3.4.260`
53+
5054
### 0.1.1
5155
+ `decodeDelimiter` setting option added.
5256
+ Updated th2 gradle plugin `0.1.6` (th2-bom: `4.9.0`)

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
kotlin.code.style=official
22
kotlin_version=1.8.22
3-
release_version=0.1.1
3+
release_version=0.1.2
44

55
vcs_url=https://github.com/th2-net/th2-codec-fix-ng

src/main/kotlin/com/exactpro/th2/codec/fixng/FixNgCodec.kt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import com.exactpro.sf.common.messages.structures.IDictionaryStructure
2323
import com.exactpro.sf.common.messages.structures.IFieldStructure
2424
import com.exactpro.sf.common.messages.structures.IMessageStructure
2525
import com.exactpro.sf.common.messages.structures.StructureUtils
26+
import com.exactpro.sf.comparison.conversion.MultiConverter
2627
import com.exactpro.th2.codec.api.IPipelineCodec
2728
import com.exactpro.th2.codec.api.IReportingContext
2829
import com.exactpro.th2.codec.fixng.FixNgCodecFactory.Companion.PROTOCOL
@@ -356,9 +357,9 @@ class FixNgCodec(dictionary: IDictionaryStructure, settings: FixNgCodecSettings)
356357
value is String -> {
357358
try {
358359
when (field.primitiveType) {
359-
LocalDateTime::class.java -> LocalDateTime.parse(value)
360-
LocalDate::class.java -> LocalDate.parse(value)
361-
LocalTime::class.java -> LocalTime.parse(value)
360+
LocalDateTime::class.java -> MultiConverter.convert<LocalDateTime>(value, LocalDateTime::class.java)
361+
LocalDate::class.java -> MultiConverter.convert<LocalDate>(value, LocalDate::class.java)
362+
LocalTime::class.java -> MultiConverter.convert<LocalTime>(value, LocalTime::class.java)
362363
java.lang.Boolean::class.java -> when {
363364
value.equals("true", true) -> true
364365
value.equals("false", true) -> false

src/test/kotlin/com/exactpro/th2/codec/fixng/FixNgCodecTest.kt

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -534,6 +534,15 @@ class FixNgCodecTest {
534534
expectedMessage = parsedMessageWithNestedGroups
535535
)
536536

537+
@ParameterizedTest
538+
@MethodSource("configs")
539+
fun `encode time zone`(isDirty: Boolean, delimiter: Char) = encodeTest(
540+
MSG_TIME_ZONE,
541+
isDirty,
542+
delimiter,
543+
parsedMessage = parsedMessageWithTimezone
544+
)
545+
537546
private fun createCodec(delimiter: Char = '', decodeValuesToStrings: Boolean = false): FixNgCodec {
538547
return FixNgCodec(dictionary, FixNgCodecSettings(
539548
dictionary = "",
@@ -873,6 +882,31 @@ class FixNgCodecTest {
873882
)
874883
)
875884

885+
private val parsedMessageWithTimezone = ParsedMessage(
886+
MessageId("test_alias", Direction.OUTGOING, 0L, Instant.now(), emptyList()),
887+
EventId("test_id", "test_book", "test_scope", Instant.now()),
888+
"TimeZoneTestMessage",
889+
mutableMapOf("encode-mode" to "dirty"),
890+
PROTOCOL,
891+
mutableMapOf(
892+
"header" to mutableMapOf(
893+
"MsgSeqNum" to 10947,
894+
"SenderCompID" to "SENDER",
895+
"SendingTime" to "2023-04-19T10:36:07.415088Z",
896+
"TargetCompID" to "RECEIVER",
897+
"BeginString" to "FIXT.1.1",
898+
"BodyLength" to 295,
899+
"MsgType" to "TEST_4"
900+
),
901+
"TransactTime" to "2018-02-05T10:38:08.000008Z",
902+
"TotalVolumeTradedDate" to "2018-02-05Z",
903+
"TotalVolumeTradedTime" to "10:38:08.000008Z",
904+
"trailer" to mutableMapOf(
905+
"CheckSum" to "122"
906+
)
907+
)
908+
)
909+
876910
companion object {
877911
private const val DIRTY_MODE_WARNING_PREFIX = "Dirty mode WARNING: "
878912

@@ -902,6 +936,7 @@ class FixNgCodecTest {
902936
private const val MSG_NESTED_OPT_COMPONENTS_MISSED_ALL_OUTER_FIELDS_AND_REQ_INNER_FIELD = "8=FIXT.1.19=5935=TEST_249=MZHOT056=INET34=12558=text_110=191"
903937

904938
private const val MSG_NESTED_GROUPS = "8=FIXT.1.19=8835=TEST_349=MZHOT056=INET34=12573=2398=3399=1399=2399=3398=3399=3399=2399=110=211"
939+
private const val MSG_TIME_ZONE = "8=FIXT.1.19=12335=TEST_449=SENDER56=RECEIVER34=1094752=20230419-10:36:07.41508860=20180205-10:38:08.000008449=20180205450=10:38:0810=206"
905940

906941
@JvmStatic
907942
fun configs() = listOf(

src/test/resources/dictionary.xml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="UTF-8"?><!--
2-
~ Copyright 2023 Exactpro (Exactpro Systems Limited)
2+
~ Copyright 2023-2024 Exactpro (Exactpro Systems Limited)
33
~
44
~ Licensed under the Apache License, Version 2.0 (the "License");
55
~ you may not use this file except in compliance with the License.
@@ -7385,6 +7385,14 @@
73857385
<attribute name="MessageType" type="java.lang.String">TEST_3</attribute>
73867386
<field name="OuterGroup" reference="component-OuterGroup"/>
73877387
</message>
7388+
<message name="TimeZoneTestMessage">
7389+
<attribute name="entity_type" type="java.lang.String">Message</attribute>
7390+
<attribute name="IsAdmin" type="java.lang.Boolean">false</attribute>
7391+
<attribute name="MessageType" type="java.lang.String">TEST_4</attribute>
7392+
<field name="TransactTime" reference="field-TransactTime" required="true"/>
7393+
<field name="TotalVolumeTradedDate" reference="field-TotalVolumeTradedDate" required="true"/>
7394+
<field name="TotalVolumeTradedTime" reference="field-TotalVolumeTradedTime" required="true"/>
7395+
</message>
73887396
<message id="component-OuterComponent" name="OuterComponent">
73897397
<attribute name="entity_type" type="java.lang.String">Component</attribute>
73907398
<field name="InnerComponent" reference="component-InnerComponent" required="true"/>

0 commit comments

Comments
 (0)