Skip to content

Commit 9e37edb

Browse files
chore(internal): swap from getNullable to getOptional (#581)
1 parent bad2b44 commit 9e37edb

File tree

200 files changed

+841
-1075
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

200 files changed

+841
-1075
lines changed

lithic-java-core/src/main/kotlin/com/lithic/api/core/Values.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -132,11 +132,11 @@ sealed class JsonField<out T : Any> {
132132
}
133133

134134
@JvmSynthetic
135-
internal fun getNullable(name: String): T? =
135+
internal fun getOptional(name: String): Optional<@UnsafeVariance T> =
136136
when (this) {
137-
is KnownValue -> value
138-
is JsonMissing -> null
139-
is JsonNull -> null
137+
is KnownValue -> Optional.of(value)
138+
is JsonMissing,
139+
is JsonNull -> Optional.empty()
140140
else -> throw LithicInvalidDataException("`$name` is invalid, received $this")
141141
}
142142

lithic-java-core/src/main/kotlin/com/lithic/api/models/Account.kt

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ private constructor(
8484
* @throws LithicInvalidDataException if the JSON field has an unexpected type (e.g. if the
8585
* server responded with an unexpected value).
8686
*/
87-
fun created(): Optional<OffsetDateTime> = Optional.ofNullable(created.getNullable("created"))
87+
fun created(): Optional<OffsetDateTime> = created.getOptional("created")
8888

8989
/**
9090
* Spend limit information for the user containing the daily, monthly, and lifetime spend limit
@@ -116,8 +116,7 @@ private constructor(
116116
* @throws LithicInvalidDataException if the JSON field has an unexpected type (e.g. if the
117117
* server responded with an unexpected value).
118118
*/
119-
fun accountHolder(): Optional<AccountHolder> =
120-
Optional.ofNullable(accountHolder.getNullable("account_holder"))
119+
fun accountHolder(): Optional<AccountHolder> = accountHolder.getOptional("account_holder")
121120

122121
/**
123122
* List of identifiers for the Auth Rule(s) that are applied on the account. This field is
@@ -129,8 +128,7 @@ private constructor(
129128
* server responded with an unexpected value).
130129
*/
131130
@Deprecated("deprecated")
132-
fun authRuleTokens(): Optional<List<String>> =
133-
Optional.ofNullable(authRuleTokens.getNullable("auth_rule_tokens"))
131+
fun authRuleTokens(): Optional<List<String>> = authRuleTokens.getOptional("auth_rule_tokens")
134132

135133
/**
136134
* 3-character alphabetic ISO 4217 code for the currency of the cardholder.
@@ -139,15 +137,15 @@ private constructor(
139137
* server responded with an unexpected value).
140138
*/
141139
fun cardholderCurrency(): Optional<String> =
142-
Optional.ofNullable(cardholderCurrency.getNullable("cardholder_currency"))
140+
cardholderCurrency.getOptional("cardholder_currency")
143141

144142
/**
145143
* @throws LithicInvalidDataException if the JSON field has an unexpected type (e.g. if the
146144
* server responded with an unexpected value).
147145
*/
148146
@Deprecated("deprecated")
149147
fun verificationAddress(): Optional<VerificationAddress> =
150-
Optional.ofNullable(verificationAddress.getNullable("verification_address"))
148+
verificationAddress.getOptional("verification_address")
151149

152150
/**
153151
* Returns the raw JSON value of [token].
@@ -1254,7 +1252,7 @@ private constructor(
12541252
* @throws LithicInvalidDataException if the JSON field has an unexpected type (e.g. if the
12551253
* server responded with an unexpected value).
12561254
*/
1257-
fun address2(): Optional<String> = Optional.ofNullable(address2.getNullable("address2"))
1255+
fun address2(): Optional<String> = address2.getOptional("address2")
12581256

12591257
/**
12601258
* Returns the raw JSON value of [address1].

lithic-java-core/src/main/kotlin/com/lithic/api/models/AccountHolder.kt

Lines changed: 23 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,7 @@ private constructor(
147147
* @throws LithicInvalidDataException if the JSON field has an unexpected type (e.g. if the
148148
* server responded with an unexpected value).
149149
*/
150-
fun accountToken(): Optional<String> =
151-
Optional.ofNullable(accountToken.getNullable("account_token"))
150+
fun accountToken(): Optional<String> = accountToken.getOptional("account_token")
152151

153152
/**
154153
* Only present when user_type == "BUSINESS". List of all entities with >25% ownership in the
@@ -158,7 +157,7 @@ private constructor(
158157
* server responded with an unexpected value).
159158
*/
160159
fun beneficialOwnerEntities(): Optional<List<AccountHolderBusinessResponse>> =
161-
Optional.ofNullable(beneficialOwnerEntities.getNullable("beneficial_owner_entities"))
160+
beneficialOwnerEntities.getOptional("beneficial_owner_entities")
162161

163162
/**
164163
* Only present when user_type == "BUSINESS". List of all individuals with >25% ownership in the
@@ -168,7 +167,7 @@ private constructor(
168167
* server responded with an unexpected value).
169168
*/
170169
fun beneficialOwnerIndividuals(): Optional<List<AccountHolderIndividualResponse>> =
171-
Optional.ofNullable(beneficialOwnerIndividuals.getNullable("beneficial_owner_individuals"))
170+
beneficialOwnerIndividuals.getOptional("beneficial_owner_individuals")
172171

173172
/**
174173
* Only applicable for customers using the KYC-Exempt workflow to enroll authorized users of
@@ -179,7 +178,7 @@ private constructor(
179178
* server responded with an unexpected value).
180179
*/
181180
fun businessAccountToken(): Optional<String> =
182-
Optional.ofNullable(businessAccountToken.getNullable("business_account_token"))
181+
businessAccountToken.getOptional("business_account_token")
183182

184183
/**
185184
* Only present when user_type == "BUSINESS". Information about the business for which the
@@ -189,7 +188,7 @@ private constructor(
189188
* server responded with an unexpected value).
190189
*/
191190
fun businessEntity(): Optional<AccountHolderBusinessResponse> =
192-
Optional.ofNullable(businessEntity.getNullable("business_entity"))
191+
businessEntity.getOptional("business_entity")
193192

194193
/**
195194
* Only present when user_type == "BUSINESS". An individual with significant responsibility for
@@ -203,7 +202,7 @@ private constructor(
203202
* server responded with an unexpected value).
204203
*/
205204
fun controlPerson(): Optional<AccountHolderIndividualResponse> =
206-
Optional.ofNullable(controlPerson.getNullable("control_person"))
205+
controlPerson.getOptional("control_person")
207206

208207
/**
209208
* < Deprecated. Use control_person.email when user_type == "BUSINESS". Use
@@ -213,16 +212,15 @@ private constructor(
213212
* @throws LithicInvalidDataException if the JSON field has an unexpected type (e.g. if the
214213
* server responded with an unexpected value).
215214
*/
216-
fun email(): Optional<String> = Optional.ofNullable(email.getNullable("email"))
215+
fun email(): Optional<String> = email.getOptional("email")
217216

218217
/**
219218
* The type of KYC exemption for a KYC-Exempt Account Holder.
220219
*
221220
* @throws LithicInvalidDataException if the JSON field has an unexpected type (e.g. if the
222221
* server responded with an unexpected value).
223222
*/
224-
fun exemptionType(): Optional<ExemptionType> =
225-
Optional.ofNullable(exemptionType.getNullable("exemption_type"))
223+
fun exemptionType(): Optional<ExemptionType> = exemptionType.getOptional("exemption_type")
226224

227225
/**
228226
* Customer-provided token that indicates a relationship with an object outside of the Lithic
@@ -231,7 +229,7 @@ private constructor(
231229
* @throws LithicInvalidDataException if the JSON field has an unexpected type (e.g. if the
232230
* server responded with an unexpected value).
233231
*/
234-
fun externalId(): Optional<String> = Optional.ofNullable(externalId.getNullable("external_id"))
232+
fun externalId(): Optional<String> = externalId.getOptional("external_id")
235233

236234
/**
237235
* Only present when user_type == "INDIVIDUAL". Information about the individual for which the
@@ -241,16 +239,15 @@ private constructor(
241239
* server responded with an unexpected value).
242240
*/
243241
fun individual(): Optional<AccountHolderIndividualResponse> =
244-
Optional.ofNullable(individual.getNullable("individual"))
242+
individual.getOptional("individual")
245243

246244
/**
247245
* Only present when user_type == "BUSINESS". User-submitted description of the business.
248246
*
249247
* @throws LithicInvalidDataException if the JSON field has an unexpected type (e.g. if the
250248
* server responded with an unexpected value).
251249
*/
252-
fun natureOfBusiness(): Optional<String> =
253-
Optional.ofNullable(natureOfBusiness.getNullable("nature_of_business"))
250+
fun natureOfBusiness(): Optional<String> = natureOfBusiness.getOptional("nature_of_business")
254251

255252
/**
256253
* < Deprecated. Use control_person.phone_number when user_type == "BUSINESS". Use
@@ -260,8 +257,7 @@ private constructor(
260257
* @throws LithicInvalidDataException if the JSON field has an unexpected type (e.g. if the
261258
* server responded with an unexpected value).
262259
*/
263-
fun phoneNumber(): Optional<String> =
264-
Optional.ofNullable(phoneNumber.getNullable("phone_number"))
260+
fun phoneNumber(): Optional<String> = phoneNumber.getOptional("phone_number")
265261

266262
/**
267263
* Only present for "KYB_BASIC" workflow. A list of documents required for the account holder to
@@ -271,7 +267,7 @@ private constructor(
271267
* server responded with an unexpected value).
272268
*/
273269
fun requiredDocuments(): Optional<List<RequiredDocument>> =
274-
Optional.ofNullable(requiredDocuments.getNullable("required_documents"))
270+
requiredDocuments.getOptional("required_documents")
275271

276272
/**
277273
* <Deprecated. Use verification_application.status instead>
@@ -284,16 +280,15 @@ private constructor(
284280
* @throws LithicInvalidDataException if the JSON field has an unexpected type (e.g. if the
285281
* server responded with an unexpected value).
286282
*/
287-
fun status(): Optional<Status> = Optional.ofNullable(status.getNullable("status"))
283+
fun status(): Optional<Status> = status.getOptional("status")
288284

289285
/**
290286
* <Deprecated. Use verification_application.status_reasons> Reason for the evaluation status.
291287
*
292288
* @throws LithicInvalidDataException if the JSON field has an unexpected type (e.g. if the
293289
* server responded with an unexpected value).
294290
*/
295-
fun statusReasons(): Optional<List<StatusReason>> =
296-
Optional.ofNullable(statusReasons.getNullable("status_reasons"))
291+
fun statusReasons(): Optional<List<StatusReason>> = statusReasons.getOptional("status_reasons")
297292

298293
/**
299294
* The type of Account Holder. If the type is "INDIVIDUAL", the "individual" attribute will be
@@ -304,7 +299,7 @@ private constructor(
304299
* @throws LithicInvalidDataException if the JSON field has an unexpected type (e.g. if the
305300
* server responded with an unexpected value).
306301
*/
307-
fun userType(): Optional<UserType> = Optional.ofNullable(userType.getNullable("user_type"))
302+
fun userType(): Optional<UserType> = userType.getOptional("user_type")
308303

309304
/**
310305
* Information about the most recent identity verification attempt
@@ -313,15 +308,15 @@ private constructor(
313308
* server responded with an unexpected value).
314309
*/
315310
fun verificationApplication(): Optional<AccountHolderVerificationApplication> =
316-
Optional.ofNullable(verificationApplication.getNullable("verification_application"))
311+
verificationApplication.getOptional("verification_application")
317312

318313
/**
319314
* Only present when user_type == "BUSINESS". Business's primary website.
320315
*
321316
* @throws LithicInvalidDataException if the JSON field has an unexpected type (e.g. if the
322317
* server responded with an unexpected value).
323318
*/
324-
fun websiteUrl(): Optional<String> = Optional.ofNullable(websiteUrl.getNullable("website_url"))
319+
fun websiteUrl(): Optional<String> = websiteUrl.getOptional("website_url")
325320

326321
/**
327322
* Returns the raw JSON value of [token].
@@ -1187,8 +1182,7 @@ private constructor(
11871182
* @throws LithicInvalidDataException if the JSON field has an unexpected type (e.g. if the
11881183
* server responded with an unexpected value).
11891184
*/
1190-
fun parentCompany(): Optional<String> =
1191-
Optional.ofNullable(parentCompany.getNullable("parent_company"))
1185+
fun parentCompany(): Optional<String> = parentCompany.getOptional("parent_company")
11921186

11931187
/**
11941188
* Returns the raw JSON value of [address].
@@ -2564,8 +2558,7 @@ private constructor(
25642558
* @throws LithicInvalidDataException if the JSON field has an unexpected type (e.g. if the
25652559
* server responded with an unexpected value).
25662560
*/
2567-
fun created(): Optional<OffsetDateTime> =
2568-
Optional.ofNullable(created.getNullable("created"))
2561+
fun created(): Optional<OffsetDateTime> = created.getOptional("created")
25692562

25702563
/**
25712564
* KYC and KYB evaluation states.
@@ -2576,7 +2569,7 @@ private constructor(
25762569
* @throws LithicInvalidDataException if the JSON field has an unexpected type (e.g. if the
25772570
* server responded with an unexpected value).
25782571
*/
2579-
fun status(): Optional<Status> = Optional.ofNullable(status.getNullable("status"))
2572+
fun status(): Optional<Status> = status.getOptional("status")
25802573

25812574
/**
25822575
* Reason for the evaluation status.
@@ -2585,16 +2578,15 @@ private constructor(
25852578
* server responded with an unexpected value).
25862579
*/
25872580
fun statusReasons(): Optional<List<StatusReason>> =
2588-
Optional.ofNullable(statusReasons.getNullable("status_reasons"))
2581+
statusReasons.getOptional("status_reasons")
25892582

25902583
/**
25912584
* Timestamp of when the application was last updated.
25922585
*
25932586
* @throws LithicInvalidDataException if the JSON field has an unexpected type (e.g. if the
25942587
* server responded with an unexpected value).
25952588
*/
2596-
fun updated(): Optional<OffsetDateTime> =
2597-
Optional.ofNullable(updated.getNullable("updated"))
2589+
fun updated(): Optional<OffsetDateTime> = updated.getOptional("updated")
25982590

25992591
/**
26002592
* Returns the raw JSON value of [created].

lithic-java-core/src/main/kotlin/com/lithic/api/models/AccountHolderCreateResponse.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ private constructor(
104104
* @throws LithicInvalidDataException if the JSON field has an unexpected type (e.g. if the
105105
* server responded with an unexpected value).
106106
*/
107-
fun created(): Optional<OffsetDateTime> = Optional.ofNullable(created.getNullable("created"))
107+
fun created(): Optional<OffsetDateTime> = created.getOptional("created")
108108

109109
/**
110110
* Customer-provided token that indicates a relationship with an object outside of the Lithic
@@ -113,7 +113,7 @@ private constructor(
113113
* @throws LithicInvalidDataException if the JSON field has an unexpected type (e.g. if the
114114
* server responded with an unexpected value).
115115
*/
116-
fun externalId(): Optional<String> = Optional.ofNullable(externalId.getNullable("external_id"))
116+
fun externalId(): Optional<String> = externalId.getOptional("external_id")
117117

118118
/**
119119
* Only present for "KYB_BASIC" workflow. A list of documents required for the account holder to
@@ -123,7 +123,7 @@ private constructor(
123123
* server responded with an unexpected value).
124124
*/
125125
fun requiredDocuments(): Optional<List<RequiredDocument>> =
126-
Optional.ofNullable(requiredDocuments.getNullable("required_documents"))
126+
requiredDocuments.getOptional("required_documents")
127127

128128
/**
129129
* Returns the raw JSON value of [token].

lithic-java-core/src/main/kotlin/com/lithic/api/models/AccountHolderListDocumentsResponse.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ private constructor(
3333
* @throws LithicInvalidDataException if the JSON field has an unexpected type (e.g. if the
3434
* server responded with an unexpected value).
3535
*/
36-
fun data(): Optional<List<Document>> = Optional.ofNullable(data.getNullable("data"))
36+
fun data(): Optional<List<Document>> = data.getOptional("data")
3737

3838
/**
3939
* Returns the raw JSON value of [data].

lithic-java-core/src/main/kotlin/com/lithic/api/models/AccountHolderListPage.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ private constructor(
8282
@JsonProperty("has_more") hasMore: JsonField<Boolean> = JsonMissing.of(),
8383
) : this(data, hasMore, mutableMapOf())
8484

85-
fun data(): List<AccountHolder> = data.getNullable("data") ?: listOf()
85+
fun data(): List<AccountHolder> = data.getOptional("data").getOrNull() ?: listOf()
8686

8787
fun hasMore(): Boolean = hasMore.getRequired("has_more")
8888

lithic-java-core/src/main/kotlin/com/lithic/api/models/AccountHolderListPageAsync.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import java.util.Optional
1818
import java.util.concurrent.CompletableFuture
1919
import java.util.concurrent.Executor
2020
import java.util.function.Predicate
21+
import kotlin.jvm.optionals.getOrNull
2122

2223
/** Get a list of individual or business account holders and their KYC or KYB evaluation status. */
2324
class AccountHolderListPageAsync
@@ -84,7 +85,7 @@ private constructor(
8485
@JsonProperty("has_more") hasMore: JsonField<Boolean> = JsonMissing.of(),
8586
) : this(data, hasMore, mutableMapOf())
8687

87-
fun data(): List<AccountHolder> = data.getNullable("data") ?: listOf()
88+
fun data(): List<AccountHolder> = data.getOptional("data").getOrNull() ?: listOf()
8889

8990
fun hasMore(): Boolean = hasMore.getRequired("has_more")
9091

lithic-java-core/src/main/kotlin/com/lithic/api/models/AccountHolderSimulateEnrollmentDocumentReviewParams.kt

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -421,9 +421,7 @@ private constructor(
421421
* server responded with an unexpected value).
422422
*/
423423
fun acceptedEntityStatusReasons(): Optional<List<String>> =
424-
Optional.ofNullable(
425-
acceptedEntityStatusReasons.getNullable("accepted_entity_status_reasons")
426-
)
424+
acceptedEntityStatusReasons.getOptional("accepted_entity_status_reasons")
427425

428426
/**
429427
* Status reason that will be associated with the simulated account holder status. Only
@@ -433,7 +431,7 @@ private constructor(
433431
* server responded with an unexpected value).
434432
*/
435433
fun statusReason(): Optional<DocumentUploadStatusReasons> =
436-
Optional.ofNullable(statusReason.getNullable("status_reason"))
434+
statusReason.getOptional("status_reason")
437435

438436
/**
439437
* Returns the raw JSON value of [documentUploadToken].

lithic-java-core/src/main/kotlin/com/lithic/api/models/AccountHolderSimulateEnrollmentReviewParams.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -346,15 +346,15 @@ private constructor(
346346
* server responded with an unexpected value).
347347
*/
348348
fun accountHolderToken(): Optional<String> =
349-
Optional.ofNullable(accountHolderToken.getNullable("account_holder_token"))
349+
accountHolderToken.getOptional("account_holder_token")
350350

351351
/**
352352
* An account holder's status for use within the simulation.
353353
*
354354
* @throws LithicInvalidDataException if the JSON field has an unexpected type (e.g. if the
355355
* server responded with an unexpected value).
356356
*/
357-
fun status(): Optional<Status> = Optional.ofNullable(status.getNullable("status"))
357+
fun status(): Optional<Status> = status.getOptional("status")
358358

359359
/**
360360
* Status reason that will be associated with the simulated account holder status. Only
@@ -364,7 +364,7 @@ private constructor(
364364
* server responded with an unexpected value).
365365
*/
366366
fun statusReasons(): Optional<List<StatusReason>> =
367-
Optional.ofNullable(statusReasons.getNullable("status_reasons"))
367+
statusReasons.getOptional("status_reasons")
368368

369369
/**
370370
* Returns the raw JSON value of [accountHolderToken].

0 commit comments

Comments
 (0)