Skip to content

Commit 7e59d99

Browse files
chore(internal): codegen related update
1 parent 184ead0 commit 7e59d99

1 file changed

Lines changed: 15 additions & 6 deletions

File tree

finch-java-core/src/main/kotlin/com/tryfinch/api/models/WebhookEvent.kt

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import com.tryfinch.api.core.getOrThrow
1717
import com.tryfinch.api.errors.FinchInvalidDataException
1818
import java.util.Objects
1919
import java.util.Optional
20+
import kotlin.jvm.optionals.getOrNull
2021

2122
@JsonDeserialize(using = WebhookEvent.Deserializer::class)
2223
@JsonSerialize(using = WebhookEvent.Serializer::class)
@@ -292,18 +293,26 @@ private constructor(
292293

293294
override fun ObjectCodec.deserialize(node: JsonNode): WebhookEvent {
294295
val json = JsonValue.fromJsonNode(node)
296+
val eventType = json.asObject().getOrNull()?.get("event_type")?.asString()?.getOrNull()
297+
298+
when (eventType) {
299+
"account.updated" -> {
300+
return tryDeserialize(node, jacksonTypeRef<AccountUpdateEvent>())?.let {
301+
WebhookEvent(accountUpdated = it, _json = json)
302+
} ?: WebhookEvent(_json = json)
303+
}
304+
"company.updated" -> {
305+
return tryDeserialize(node, jacksonTypeRef<CompanyEvent>())?.let {
306+
WebhookEvent(companyUpdated = it, _json = json)
307+
} ?: WebhookEvent(_json = json)
308+
}
309+
}
295310

296311
val bestMatches =
297312
sequenceOf(
298-
tryDeserialize(node, jacksonTypeRef<AccountUpdateEvent>())?.let {
299-
WebhookEvent(accountUpdated = it, _json = json)
300-
},
301313
tryDeserialize(node, jacksonTypeRef<JobCompletionEvent>())?.let {
302314
WebhookEvent(jobCompletion = it, _json = json)
303315
},
304-
tryDeserialize(node, jacksonTypeRef<CompanyEvent>())?.let {
305-
WebhookEvent(companyUpdated = it, _json = json)
306-
},
307316
tryDeserialize(node, jacksonTypeRef<DirectoryEvent>())?.let {
308317
WebhookEvent(directory = it, _json = json)
309318
},

0 commit comments

Comments
 (0)