Arnab
08/28/2023, 2:32 PMattachments of type Attachment but it can be either a FileAttachment og PullRequest or even something else. I can make lenses for both subtypes and the supertype but I don’t understand how to check if it is one or the other? To be clear, the two types are mixed in the response.Arnab
08/28/2023, 2:34 PMid and isUpload field and discriminate between them, and then make a separate response to get them one by one, but that sounds extremely tedious and bad 😞dave
08/28/2023, 2:38 PMArnab
08/28/2023, 2:40 PMs4nchez
08/28/2023, 2:55 PMArnab
08/28/2023, 3:05 PMcallTrelloApi("cards/${id}/attachments").let {
        it.bodyString().asJsonObject().map { attachment ->
            attachment["isUpload"].booleanValue() to
                    Response(Status.OK).with(Body.json().toLens() of attachment)
        }.map { (isUpload, attachmentResponse) ->
            if (isUpload) fileAttachmentLens(attachmentResponse) else githubPRLens(attachmentResponse)
        }
    }
This sorta works, but I do wish there was a way to write :
val attachmentLens = Body.auto<Attachment>().toLens()
and then link it somehow to the lenses I created for FileAttachment and GithubPRAttachment but doesn’t seem to be the case 😛Andrew O'Hara
08/28/2023, 3:25 PMJsonTypeInfo.As.EXISTING_PROPERTY and add the property to the base class rather than it be implied.
https://stackoverflow.com/a/30386694/1253613Andrew O'Hara
08/28/2023, 4:00 PM@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.EXISTING_PROPERTY, property = "type")
@JsonSubTypes(
    JsonSubTypes.Type(value = IntOptionsDtoV5.Range::class, name = "range"),
    JsonSubTypes.Type(value = IntOptionsDtoV5.List::class, name = "list"),
)
sealed class IntOptionsDtoV5(val type: String) {
    data class Range(val min: Int, val max: Int): IntOptionsDtoV5("range")
    data class List(val values: kotlin.collections.List<Int>): IntOptionsDtoV5("list")
    companion object {
        val lens = Jackson.autoBody<IntOptionsDtoV5>().toLens()
    }
}Arnab
08/28/2023, 7:47 PM