Skip to content

Commit 630e9df

Browse files
feat: use more specific types for string types with the date, date-time, and uuid formats
feat: use more specific types for string types with the date, date-time, and uuid formats
1 parent b1518c5 commit 630e9df

32 files changed

Lines changed: 186 additions & 160 deletions

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
package com.lithic.api.core
44

55
import com.fasterxml.jackson.annotation.JsonInclude
6+
import com.fasterxml.jackson.databind.DeserializationFeature
67
import com.fasterxml.jackson.databind.SerializationFeature
78
import com.fasterxml.jackson.databind.cfg.CoercionAction.Fail
89
import com.fasterxml.jackson.databind.cfg.CoercionInputShape.Integer
@@ -16,6 +17,7 @@ fun jsonMapper(): JsonMapper =
1617
.addModule(Jdk8Module())
1718
.addModule(JavaTimeModule())
1819
.serializationInclusion(JsonInclude.Include.NON_ABSENT)
20+
.disable(DeserializationFeature.ADJUST_DATES_TO_CONTEXT_TIME_ZONE)
1921
.disable(SerializationFeature.FLUSH_AFTER_WRITE_VALUE)
2022
.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS)
2123
.disable(SerializationFeature.WRITE_DURATIONS_AS_TIMESTAMPS)

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

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,7 @@ sealed class JsonField<out T : Any> {
8383
is KnownValue -> value
8484
is JsonMissing -> throw LithicInvalidDataException("'${name}' is not set")
8585
is JsonNull -> throw LithicInvalidDataException("'${name}' is null")
86-
else ->
87-
throw LithicInvalidDataException(
88-
"'${name}' is invalid; received ${this.toString()}"
89-
)
86+
else -> throw LithicInvalidDataException("'${name}' is invalid, received ${this}")
9087
}
9188

9289
@JvmSynthetic
@@ -95,10 +92,7 @@ sealed class JsonField<out T : Any> {
9592
is KnownValue -> value
9693
is JsonMissing -> null
9794
is JsonNull -> null
98-
else ->
99-
throw LithicInvalidDataException(
100-
"'${name}' is invalid; received ${this.toString()}"
101-
)
95+
else -> throw LithicInvalidDataException("'${name}' is invalid, received ${this}")
10296
}
10397

10498
@JvmSynthetic

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

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,23 @@ package com.lithic.api.models
33
import com.lithic.api.core.NoAutoDetect
44
import com.lithic.api.core.toUnmodifiable
55
import com.lithic.api.models.*
6+
import java.time.OffsetDateTime
67
import java.util.Objects
78
import java.util.Optional
89

910
class AccountListParams
1011
constructor(
11-
private val begin: String?,
12-
private val end: String?,
12+
private val begin: OffsetDateTime?,
13+
private val end: OffsetDateTime?,
1314
private val page: Long?,
1415
private val pageSize: Long?,
1516
private val additionalQueryParams: Map<String, List<String>>,
1617
private val additionalHeaders: Map<String, List<String>>,
1718
) {
1819

19-
fun begin(): Optional<String> = Optional.ofNullable(begin)
20+
fun begin(): Optional<OffsetDateTime> = Optional.ofNullable(begin)
2021

21-
fun end(): Optional<String> = Optional.ofNullable(end)
22+
fun end(): Optional<OffsetDateTime> = Optional.ofNullable(end)
2223

2324
fun page(): Optional<Long> = Optional.ofNullable(page)
2425

@@ -79,8 +80,8 @@ constructor(
7980
@NoAutoDetect
8081
class Builder {
8182

82-
private var begin: String? = null
83-
private var end: String? = null
83+
private var begin: OffsetDateTime? = null
84+
private var end: OffsetDateTime? = null
8485
private var page: Long? = null
8586
private var pageSize: Long? = null
8687
private var additionalQueryParams: MutableMap<String, MutableList<String>> = mutableMapOf()
@@ -100,13 +101,13 @@ constructor(
100101
* Date string in 8601 format. Only entries created after the specified date will be
101102
* included. UTC time zone.
102103
*/
103-
fun begin(begin: String) = apply { this.begin = begin }
104+
fun begin(begin: OffsetDateTime) = apply { this.begin = begin }
104105

105106
/**
106107
* Date string in 8601 format. Only entries created before the specified date will be
107108
* included. UTC time zone.
108109
*/
109-
fun end(end: String) = apply { this.end = end }
110+
fun end(end: OffsetDateTime) = apply { this.end = end }
110111

111112
/** Page (for pagination). */
112113
fun page(page: Long) = apply { this.page = page }

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,15 @@ import com.lithic.api.core.JsonValue
1212
import com.lithic.api.core.NoAutoDetect
1313
import com.lithic.api.core.toUnmodifiable
1414
import com.lithic.api.errors.LithicInvalidDataException
15+
import java.time.OffsetDateTime
1516
import java.util.Objects
1617
import java.util.Optional
1718

1819
@JsonDeserialize(builder = Card.Builder::class)
1920
@NoAutoDetect
2021
class Card
2122
private constructor(
22-
private val created: JsonField<String>,
23+
private val created: JsonField<OffsetDateTime>,
2324
private val cvv: JsonField<String>,
2425
private val funding: JsonField<FundingSource>,
2526
private val expMonth: JsonField<String>,
@@ -43,7 +44,7 @@ private constructor(
4344
private var hashCode: Int = 0
4445

4546
/** An ISO 8601 timestamp for when the card was created. UTC time zone. */
46-
fun created(): String = created.getRequired("created")
47+
fun created(): OffsetDateTime = created.getRequired("created")
4748

4849
/** Three digit cvv printed on the back of the card. */
4950
fun cvv(): Optional<String> = Optional.ofNullable(cvv.getNullable("cvv"))
@@ -338,7 +339,7 @@ private constructor(
338339

339340
class Builder {
340341

341-
private var created: JsonField<String> = JsonMissing.of()
342+
private var created: JsonField<OffsetDateTime> = JsonMissing.of()
342343
private var cvv: JsonField<String> = JsonMissing.of()
343344
private var funding: JsonField<FundingSource> = JsonMissing.of()
344345
private var expMonth: JsonField<String> = JsonMissing.of()
@@ -378,12 +379,12 @@ private constructor(
378379
}
379380

380381
/** An ISO 8601 timestamp for when the card was created. UTC time zone. */
381-
fun created(created: String) = created(JsonField.of(created))
382+
fun created(created: OffsetDateTime) = created(JsonField.of(created))
382383

383384
/** An ISO 8601 timestamp for when the card was created. UTC time zone. */
384385
@JsonProperty("created")
385386
@ExcludeMissing
386-
fun created(created: JsonField<String>) = apply { this.created = created }
387+
fun created(created: JsonField<OffsetDateTime>) = apply { this.created = created }
387388

388389
/** Three digit cvv printed on the back of the card. */
389390
fun cvv(cvv: String) = cvv(JsonField.of(cvv))

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

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@ package com.lithic.api.models
33
import com.lithic.api.core.NoAutoDetect
44
import com.lithic.api.core.toUnmodifiable
55
import com.lithic.api.models.*
6+
import java.time.OffsetDateTime
67
import java.util.Objects
78
import java.util.Optional
89

910
class CardListParams
1011
constructor(
1112
private val accountToken: String?,
12-
private val begin: String?,
13-
private val end: String?,
13+
private val begin: OffsetDateTime?,
14+
private val end: OffsetDateTime?,
1415
private val page: Long?,
1516
private val pageSize: Long?,
1617
private val additionalQueryParams: Map<String, List<String>>,
@@ -19,9 +20,9 @@ constructor(
1920

2021
fun accountToken(): Optional<String> = Optional.ofNullable(accountToken)
2122

22-
fun begin(): Optional<String> = Optional.ofNullable(begin)
23+
fun begin(): Optional<OffsetDateTime> = Optional.ofNullable(begin)
2324

24-
fun end(): Optional<String> = Optional.ofNullable(end)
25+
fun end(): Optional<OffsetDateTime> = Optional.ofNullable(end)
2526

2627
fun page(): Optional<Long> = Optional.ofNullable(page)
2728

@@ -86,8 +87,8 @@ constructor(
8687
class Builder {
8788

8889
private var accountToken: String? = null
89-
private var begin: String? = null
90-
private var end: String? = null
90+
private var begin: OffsetDateTime? = null
91+
private var end: OffsetDateTime? = null
9192
private var page: Long? = null
9293
private var pageSize: Long? = null
9394
private var additionalQueryParams: MutableMap<String, MutableList<String>> = mutableMapOf()
@@ -116,13 +117,13 @@ constructor(
116117
* Date string in 8601 format. Only entries created after the specified date will be
117118
* included. UTC time zone.
118119
*/
119-
fun begin(begin: String) = apply { this.begin = begin }
120+
fun begin(begin: OffsetDateTime) = apply { this.begin = begin }
120121

121122
/**
122123
* Date string in 8601 format. Only entries created before the specified date will be
123124
* included. UTC time zone.
124125
*/
125-
fun end(end: String) = apply { this.end = end }
126+
fun end(end: OffsetDateTime) = apply { this.end = end }
126127

127128
/** Page (for pagination). */
128129
fun page(page: Long) = apply { this.page = page }

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

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import com.lithic.api.core.JsonMissing
1010
import com.lithic.api.core.JsonValue
1111
import com.lithic.api.core.NoAutoDetect
1212
import com.lithic.api.core.toUnmodifiable
13+
import java.time.OffsetDateTime
1314
import java.util.Objects
1415
import java.util.Optional
1516

@@ -19,7 +20,7 @@ class EmbedRequestParams
1920
private constructor(
2021
private val accountToken: JsonField<String>,
2122
private val css: JsonField<String>,
22-
private val expiration: JsonField<String>,
23+
private val expiration: JsonField<OffsetDateTime>,
2324
private val token: JsonField<String>,
2425
private val targetOrigin: JsonField<String>,
2526
private val additionalProperties: Map<String, JsonValue>,
@@ -50,7 +51,8 @@ private constructor(
5051
* `expiration`, in the event that a malicious user gets a copy of your request in transit, they
5152
* will be able to obtain the response data indefinitely.
5253
*/
53-
fun expiration(): Optional<String> = Optional.ofNullable(expiration.getNullable("expiration"))
54+
fun expiration(): Optional<OffsetDateTime> =
55+
Optional.ofNullable(expiration.getNullable("expiration"))
5456

5557
/** Globally unique identifier for the card to be displayed. */
5658
fun token(): String = token.getRequired("token")
@@ -155,7 +157,7 @@ private constructor(
155157

156158
private var accountToken: JsonField<String> = JsonMissing.of()
157159
private var css: JsonField<String> = JsonMissing.of()
158-
private var expiration: JsonField<String> = JsonMissing.of()
160+
private var expiration: JsonField<OffsetDateTime> = JsonMissing.of()
159161
private var token: JsonField<String> = JsonMissing.of()
160162
private var targetOrigin: JsonField<String> = JsonMissing.of()
161163
private var additionalProperties: MutableMap<String, JsonValue> = mutableMapOf()
@@ -205,7 +207,7 @@ private constructor(
205207
* `expiration`, in the event that a malicious user gets a copy of your request in transit,
206208
* they will be able to obtain the response data indefinitely.
207209
*/
208-
fun expiration(expiration: String) = expiration(JsonField.of(expiration))
210+
fun expiration(expiration: OffsetDateTime) = expiration(JsonField.of(expiration))
209211

210212
/**
211213
* An ISO 8601 timestamp for when the request should expire. UTC time zone.
@@ -220,7 +222,9 @@ private constructor(
220222
*/
221223
@JsonProperty("expiration")
222224
@ExcludeMissing
223-
fun expiration(expiration: JsonField<String>) = apply { this.expiration = expiration }
225+
fun expiration(expiration: JsonField<OffsetDateTime>) = apply {
226+
this.expiration = expiration
227+
}
224228

225229
/** Globally unique identifier for the card to be displayed. */
226230
fun token(token: String) = token(JsonField.of(token))

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import com.lithic.api.core.JsonValue
1212
import com.lithic.api.core.NoAutoDetect
1313
import com.lithic.api.core.toUnmodifiable
1414
import com.lithic.api.errors.LithicInvalidDataException
15+
import java.time.OffsetDateTime
1516
import java.util.Objects
1617

1718
/** A single event that affects the transaction state and lifecycle. */
@@ -22,7 +23,7 @@ private constructor(
2223
private val token: JsonField<String>,
2324
private val eventType: JsonField<EventType>,
2425
private val payload: JsonField<Payload>,
25-
private val created: JsonField<String>,
26+
private val created: JsonField<OffsetDateTime>,
2627
private val additionalProperties: Map<String, JsonValue>,
2728
) {
2829

@@ -49,7 +50,7 @@ private constructor(
4950
*
5051
* If no timezone is specified, UTC will be used.
5152
*/
52-
fun created(): String = created.getRequired("created")
53+
fun created(): OffsetDateTime = created.getRequired("created")
5354

5455
/** Globally unique identifier. */
5556
@JsonProperty("token") @ExcludeMissing fun _token() = token
@@ -128,7 +129,7 @@ private constructor(
128129
private var token: JsonField<String> = JsonMissing.of()
129130
private var eventType: JsonField<EventType> = JsonMissing.of()
130131
private var payload: JsonField<Payload> = JsonMissing.of()
131-
private var created: JsonField<String> = JsonMissing.of()
132+
private var created: JsonField<OffsetDateTime> = JsonMissing.of()
132133
private var additionalProperties: MutableMap<String, JsonValue> = mutableMapOf()
133134

134135
@JvmSynthetic
@@ -179,7 +180,7 @@ private constructor(
179180
*
180181
* If no timezone is specified, UTC will be used.
181182
*/
182-
fun created(created: String) = created(JsonField.of(created))
183+
fun created(created: OffsetDateTime) = created(JsonField.of(created))
183184

184185
/**
185186
* An ISO 8601 timestamp for when the event was created. UTC time zone.
@@ -188,7 +189,7 @@ private constructor(
188189
*/
189190
@JsonProperty("created")
190191
@ExcludeMissing
191-
fun created(created: JsonField<String>) = apply { this.created = created }
192+
fun created(created: JsonField<OffsetDateTime>) = apply { this.created = created }
192193

193194
fun additionalProperties(additionalProperties: Map<String, JsonValue>) = apply {
194195
this.additionalProperties.clear()

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

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,14 @@ import com.lithic.api.core.NoAutoDetect
77
import com.lithic.api.core.toUnmodifiable
88
import com.lithic.api.errors.LithicInvalidDataException
99
import com.lithic.api.models.*
10+
import java.time.OffsetDateTime
1011
import java.util.Objects
1112
import java.util.Optional
1213

1314
class EventListParams
1415
constructor(
15-
private val begin: String?,
16-
private val end: String?,
16+
private val begin: OffsetDateTime?,
17+
private val end: OffsetDateTime?,
1718
private val pageSize: Long?,
1819
private val startingAfter: String?,
1920
private val endingBefore: String?,
@@ -22,9 +23,9 @@ constructor(
2223
private val additionalHeaders: Map<String, List<String>>,
2324
) {
2425

25-
fun begin(): Optional<String> = Optional.ofNullable(begin)
26+
fun begin(): Optional<OffsetDateTime> = Optional.ofNullable(begin)
2627

27-
fun end(): Optional<String> = Optional.ofNullable(end)
28+
fun end(): Optional<OffsetDateTime> = Optional.ofNullable(end)
2829

2930
fun pageSize(): Optional<Long> = Optional.ofNullable(pageSize)
3031

@@ -95,8 +96,8 @@ constructor(
9596
@NoAutoDetect
9697
class Builder {
9798

98-
private var begin: String? = null
99-
private var end: String? = null
99+
private var begin: OffsetDateTime? = null
100+
private var end: OffsetDateTime? = null
100101
private var pageSize: Long? = null
101102
private var startingAfter: String? = null
102103
private var endingBefore: String? = null
@@ -120,13 +121,13 @@ constructor(
120121
* Date string in 8601 format. Only entries created after the specified date will be
121122
* included. UTC time zone.
122123
*/
123-
fun begin(begin: String) = apply { this.begin = begin }
124+
fun begin(begin: OffsetDateTime) = apply { this.begin = begin }
124125

125126
/**
126127
* Date string in 8601 format. Only entries created before the specified date will be
127128
* included. UTC time zone.
128129
*/
129-
fun end(end: String) = apply { this.end = end }
130+
fun end(end: OffsetDateTime) = apply { this.end = end }
130131

131132
/** Page size (for pagination). */
132133
fun pageSize(pageSize: Long) = apply { this.pageSize = pageSize }

0 commit comments

Comments
 (0)