diff --git a/fints4javaLib/src/main/kotlin/net/dankito/fints/response/ResponseParser.kt b/fints4javaLib/src/main/kotlin/net/dankito/fints/response/ResponseParser.kt index 9c1b187b..e64bd735 100644 --- a/fints4javaLib/src/main/kotlin/net/dankito/fints/response/ResponseParser.kt +++ b/fints4javaLib/src/main/kotlin/net/dankito/fints/response/ResponseParser.kt @@ -158,14 +158,14 @@ open class ResponseParser @JvmOverloads constructor( val bankCountryCode = parseInt(accountDetails[2]) val bankCode = parseString(accountDetails[3]) - val iban = parseStringToNullIfEmpty(dataElementGroups[2]) + val iban = parseStringToNullIfEmpty(dataElementGroups[2]) // optional val customerId = parseString(dataElementGroups[3]) - val accountType = parseCodeEnum(dataElementGroups[4], AccountTypeCode.values()).type - val currency = parseString(dataElementGroups[5]) + val accountType = parseNullableCodeEnum(dataElementGroups[4], AccountTypeCode.values())?.type + val currency = parseStringToNullIfEmpty(dataElementGroups[5]) val accountHolderName1 = parseString(dataElementGroups[6]) - val accountHolderName2 = parseStringToNullIfEmpty(dataElementGroups[7]) - val productName = parseStringToNullIfEmpty(dataElementGroups[8]) - val limit = parseStringToNullIfEmpty(dataElementGroups[9]) // TODO: parse limit + val accountHolderName2 = if (dataElementGroups.size > 7) parseStringToNullIfEmpty(dataElementGroups[7]) else null + val productName = if (dataElementGroups.size > 8) parseStringToNullIfEmpty(dataElementGroups[8]) else null + val limit = if (dataElementGroups.size > 9) parseStringToNullIfEmpty(dataElementGroups[9]) else null // TODO: parse limit // TODO: parse allowed jobs // TODO: parse extension @@ -362,6 +362,14 @@ open class ResponseParser @JvmOverloads constructor( return allValues.first { it.code == code } } + protected open fun parseNullableCodeEnum(code: String, allValues: Array): T? { + try { + return parseCodeEnum(code, allValues) + } catch (ignored: Exception) { } + + return null + } + protected open fun getDataElements(dataElementGroup: String): List { return splitIntoPartsAndUnmask(dataElementGroup, Separators.DataElementsSeparator) diff --git a/fints4javaLib/src/main/kotlin/net/dankito/fints/response/segments/AccountInfo.kt b/fints4javaLib/src/main/kotlin/net/dankito/fints/response/segments/AccountInfo.kt index e06037db..8e36db4a 100644 --- a/fints4javaLib/src/main/kotlin/net/dankito/fints/response/segments/AccountInfo.kt +++ b/fints4javaLib/src/main/kotlin/net/dankito/fints/response/segments/AccountInfo.kt @@ -8,8 +8,8 @@ open class AccountInfo( val bankCode: String, val iban: String?, val customerId: String, - val accountType: AccountType, - val currency: String, // TODO: may parse to a value object + val accountType: AccountType?, + val currency: String?, // TODO: may parse to a value object val accountHolderName1: String, val accountHolderName2: String?, val productName: String?, diff --git a/fints4javaLib/src/test/kotlin/net/dankito/fints/response/ResponseParserTest.kt b/fints4javaLib/src/test/kotlin/net/dankito/fints/response/ResponseParserTest.kt index 17d5000a..e65fbaba 100644 --- a/fints4javaLib/src/test/kotlin/net/dankito/fints/response/ResponseParserTest.kt +++ b/fints4javaLib/src/test/kotlin/net/dankito/fints/response/ResponseParserTest.kt @@ -214,6 +214,33 @@ class ResponseParserTest : FinTsTestBase() { ?: run { Assert.fail("No segment of type AccountInfo found in ${result.receivedSegments}") } } + @Test + fun parseAccountInfo_OptionalFieldsNotSet() { + + // when + val result = underTest.parse("HIUPD:74:6:3+9999999999::280:10070000++9999999999+++anonym") + + // then + assertSuccessfullyParsedSegment(result, InstituteSegmentId.AccountInfo, 74, 6, 3) + + result.getFirstSegmentById(InstituteSegmentId.AccountInfo)?.let { segment -> + assertThat(segment.accountNumber).isEqualTo("9999999999") + assertThat(segment.subAccountAttribute).isNull() + assertThat(segment.bankCountryCode).isEqualTo(280) + assertThat(segment.bankCode).isEqualTo("10070000") + assertThat(segment.iban).isNull() + assertThat(segment.customerId).isEqualTo("9999999999") + assertThat(segment.accountType).isNull() + assertThat(segment.currency).isNull() + assertThat(segment.accountHolderName1).isEqualTo("anonym") + assertThat(segment.accountHolderName2).isNull() + assertThat(segment.productName).isNull() + assertThat(segment.accountLimit).isNull() + assertThat(segment.extension).isNull() + } + ?: run { Assert.fail("No segment of type AccountInfo found in ${result.receivedSegments}") } + } + @Test fun parseTanInfo() {