https://kotlinlang.org logo
Docs
Join the conversationJoin Slack
Channels
100daysofcode
100daysofkotlin
100daysofkotlin-2021
advent-of-code
aem
ai
alexa
algeria
algolialibraries
amsterdam
android
android-architecture
android-databinding
android-studio
androidgithubprojects
androidthings
androidx
androidx-xprocessing
anime
anko
announcements
apollo-kotlin
appintro
arabic
argentina
arkenv
arksemdevteam
armenia
arrow
arrow-contributors
arrow-meta
ass
atlanta
atm17
atrium
austin
australia
austria
awesome-kotlin
ballast
bangladesh
barcelona
bayarea
bazel
beepiz-libraries
belgium
berlin
big-data
books
boston
brazil
brikk
budapest
build
build-tools
bulgaria
bydgoszcz
cambodia
canada
carrat
carrat-dev
carrat-feed
chicago
chile
china
chucker
cincinnati-user-group
cli
clikt
cloudfoundry
cn
cobalt
code-coverage
codeforces
codemash-precompiler
codereview
codingame
codingconventions
coimbatore
collaborations
colombia
colorado
communities
competitive-programming
competitivecoding
compiler
compose
compose-android
compose-desktop
compose-hiring
compose-ios
compose-mp
compose-ui-showcase
compose-wear
compose-web
connect-audit-events
corda
cork
coroutines
couchbase
coursera
croatia
cryptography
cscenter-course-2016
cucumber-bdd
cyprus
czech
dagger
data2viz
databinding
datascience
dckotlin
debugging
decompose
decouple
denmark
deprecated
detekt
detekt-hint
dev-core
dfw
docs-revamped
dokka
domain-driven-design
doodle
dsl
dublin
dutch
eap
eclipse
ecuador
edinburgh
education
effective-kotlin
effectivekotlin
emacs
embedded-kotlin
estatik
event21-community-content
events
exposed
failgood
fb-internal-demo
feed
firebase
flow
fluid-libraries
forkhandles
forum
fosdem
fp-in-kotlin
framework-elide
freenode
french
fritz2
fuchsia
functional
funktionale
gamedev
ge-kotlin
general-advice
georgia
geospatial
german-lang
getting-started
github-workflows-kt
glance
godot-kotlin
google-io
gradle
graphic
graphkool
graphql
graphql-kotlin
graviton-browser
greece
grpc
gsoc
gui
hackathons
hacktoberfest
hamburg
hamkrest
helios
helsinki
hexagon
hibernate
hikari-cp
hire-me
hiring
hongkong
hoplite
http4k
hungary
hyderabad
image-processing
india
indonesia
inkremental
intellij
intellij-plugins
intellij-tricks
internships
introduce-yourself
io
ios
iran
israel
istanbulcoders
italian
jackson-kotlin
jadx
japanese
jasync-sql
java-to-kotlin-refactoring
javadevelopers
javafx
javalin
javascript
jdbi
jhipster-kotlin
jobsworldwide
jpa
jshdq
juul-libraries
jvm-ir-backend-feedback
jxadapter
k2-early-adopters
kaal
kafka
kakao
kalasim
kapt
karachi
karg
karlsruhe
kash_shell
kaskade
kbuild
kdbc
kgen-doc-tools
kgraphql
kinta
klaxon
klock
kloudformation
kmdc
kmm-español
kmongo
knbt
knote
koalaql
koans
kobalt
kobweb
kodein
kodex
kohesive
koin
koin-dev
komapper
kondor-json
kong
kontent
kontributors
korau
korean
korge
korim
korio
korlibs
korte
kotest
kotest-contributors
kotless
kotlick
kotlin-asia
kotlin-beam
kotlin-by-example
kotlin-csv
kotlin-data-storage
kotlin-foundation
kotlin-fuel
kotlin-in-action
kotlin-inject
kotlin-latam
kotlin-logging
kotlin-multiplatform-contest
kotlin-mumbai
kotlin-native
kotlin-pakistan
kotlin-plugin
kotlin-pune
kotlin-roadmap
kotlin-samples
kotlin-sap
kotlin-serbia
kotlin-spark
kotlin-szeged
kotlin-website
kotlinacademy
kotlinbot
kotlinconf
kotlindl
kotlinforbeginners
kotlingforbeginners
kotlinlondon
kotlinmad
kotlinprogrammers
kotlinsu
kotlintest
kotlintest-devs
kotlintlv
kotlinultimatechallenge
kotlinx-datetime
kotlinx-files
kotlinx-html
kotrix
kotson
kovenant
kprompt
kraph
krawler
kroto-plus
ksp
ktcc
ktfmt
ktlint
ktor
ktp
kubed
kug-leads
kug-torino
kvision
kweb
lambdaworld_cadiz
lanark
language-evolution
language-proposals
latvia
leakcanary
leedskotlinusergroup
lets-have-fun
libgdx
libkgd
library-development
linkeddata
lithuania
london
losangeles
lottie
love
lychee
macedonia
machinelearningbawas
madrid
malaysia
mathematics
meetkotlin
memes
meta
metro-detroit
mexico
miami
micronaut
minnesota
minutest
mirror
mockk
moko
moldova
monsterpuzzle
montreal
moonbean
morocco
motionlayout
mpapt
mu
multiplatform
mumbai
munich
mvikotlin
mvrx
myndocs-oauth2-server
naming
navigation-architecture-component
nepal
new-mexico
new-zealand
newname
nigeria
nodejs
norway
npm-publish
nyc
oceania
ohio-kotlin-users
oldenburg
oolong
opensource
orbit-mvi
osgi
otpisani
package-search
pakistan
panamá
pattern-matching
pbandk
pdx
peru
philippines
phoenix
pinoy
pocketgitclient
polish
popkorn
portugal
practical-functional-programming
proguard
prozis-android-backup
pyhsikal
python
python-contributors
quasar
random
re
react
reaktive
realm
realworldkotlin
reductor
reduks
redux
redux-kotlin
refactoring-to-kotlin
reflect
refreshversions
reports
result
rethink
revolver
rhein-main
rocksdb
romania
room
rpi-pico
rsocket
russian
russian_feed
russian-kotlinasfirst
rx
rxjava
san-diego
science
scotland
scrcast
scrimage
script
scripting
seattle
serialization
server
sg-user-group
singapore
skia-wasm-interop-temp
skrape-it
slovak
snake
sofl-user-group
southafrica
spacemacs
spain
spanish
speaking
spek
spin
splitties
spotify-mobius
spring
spring-security
squarelibraries
stackoverflow
stacks
stayhungrystayfoolish
stdlib
stlouis
strife-discord-lib
strikt
students
stuttgart
sudan
swagger-gradle-codegen
swarm
sweden
swing
swiss-user-group
switzerland
talking-kotlin
tallinn
tampa
teamcity
tegal
tempe
tensorflow
terminal
test
testing
testtestest
texas
tgbotapi
thailand
tornadofx
touchlab-tools
training
tricity-kotlin-user-group
trójmiasto
truth
tunisia
turkey
turkiye
twitter-feed
uae
udacityindia
uk
ukrainian
uniflow
unkonf
uruguay
utah
uuid
vancouver
vankotlin
vertx
videos
vienna
vietnam
vim
vkug
vuejs
web-mpp
webassembly
webrtc
wimix_sentry
wwdc
zircon
Powered by Linen
server
  • a

    Alina Grebenkina

    04/26/2022, 3:00 PM
    Join us on May 10 for Event Streaming with Apache Pulsar and Kotlin. In this webinar, we will demonstrate how to enhance event-driven microservices with advanced capabilities, such as on-the-fly serialization or parallel processing. Save the date: https://kotl.in/9ya3p9
    🎉 9
    👍 5
    d
    • 2
    • 1
  • g

    Gillian Buijs

    05/04/2022, 4:35 PM
    Given a classic maven based Java EE app running on Websphere Liberty with Angular frontend, would it be feasible to port it to KMP? We started using Kotlin in the backend instead of Java. I would want to ditch the Angular frontend (it's old and made badly) and use React with Kotlin/JS. Primary benefit would be typesafe coupling between frontend and backend and using Kotlin for both (instead of TS yuck). Ideally I would want to use the backend as-is and keep the Gradle usage to a bare minimum because everything is maven based (company policy). Kind of a broad question I know, but if anyone has some experience/advice it's appreciated 👍
    a
    • 2
    • 2
  • m

    Marco Pierucci

    05/05/2022, 4:00 PM
    Hello! Is there any good alternative to KgraphQL ? Joined a team that was using this to mock a graphql endpoint on an android project. But seems that has usages of MethodHandle.invoke and MethodHandle.invokeExact which wont allow me to run under api 26
    m
    r
    d
    • 4
    • 8
  • a

    André Martins

    05/05/2022, 4:18 PM
    Hello, I’m trying to measure the time it takes to execute a function although I want to log the time it took even if the function throws any exception. I came up with this approach but seems ugly to me. What you guys think? Is there any other approach?
    val (result, duration) = measureTimedValue {
        try {
            foo()
        } catch (ex: Throwable) {
            ex
        }
    }
    when(result) {
        is Throwable -> println("Error ${duration.inWholeMilliseconds} ms")
        else -> println("Success ${duration.inWholeMilliseconds} ms")
    }
    h
    • 2
    • 3
  • k

    Kristian Nedrevold

    05/05/2022, 6:41 PM
    Is there a good database framework/abstraction layer in kotlin that uses a non-blocking driver? I am implementing a ktor backend with a postgres database, and am looking for something like jdbi that uses a non-blocking driver.
    t
    a
    • 3
    • 3
  • m

    mbonnin

    05/09/2022, 2:32 PM
    Is there a public Docker image that comes with kotlin preinstalled that I could build upon ?
    p
    n
    • 3
    • 15
  • j

    Jarkko Miettinen

    05/10/2022, 10:24 AM
    Hey, I ended up with doing silly things with Redis and storing a changed class there with same key as earlier. This of course blew up my retrieval code as older versions could not be deserialized from JSON anymore. Any thoughts on how versioning of such (data?) classes could be automated? I am thinking of creating a simple object graph traversal that mostly allows for simple collections and basic types. But that seems like a lot of work for something that I think has been solved already. So what's the best way to store potentially changing Kotlin objects, serialized as JSON, to Redis?
    a
    e
    d
    • 4
    • 9
  • k

    Kevin Del Castillo

    05/10/2022, 10:15 PM
    Is it wise to run an API server with Kotlin/Native or is it preferred to run it with the JVM for now?
    n
    a
    • 3
    • 2
  • a

    Andrzej Sawoniewicz

    05/13/2022, 2:17 PM
    Hi guys. In our project there is a lot of boilerplate code and I am considering migrate to Kotlin. However we have 3 layers of model classes (ATO, actual model, DTO) and therefore we use mappers heavily (with complex composition structure). For now we use Remap but it is not working too well with Kotlin. I was considering to switch to MapStruct but it is also not supporting the Kotlin directly. There is a library to create builders automatically but it is rather simple and not supported anymore. What do you think would be the best solution here? Manual mapping, MapStruct or something else?
    m
    m
    • 3
    • 3
  • s

    stvn

    05/14/2022, 1:40 PM
    Hey, im learning jwt-authorization with Ktor using this tutorial https://ktor.io/docs/jwt.html#flow , my question is for tips how to generate safe shared secret and is there some requirements for it? i’m planning storing it in Heroku config-var.
    a
    • 2
    • 1
  • f

    fulstaph

    05/14/2022, 2:21 PM
    Hello! I'm trying to implement web service usig Ktor and Exposed. The server itself works fine, but application tests are failing without an active database connection.
    class ApplicationTest {
        @Test
        fun testRoot() = testApplication {
            val response = client.get("/")
            assertEquals(HttpStatusCode.OK, response.status)
        }
    }
    basically this sample test is failing because it seems like
    testApplication
    tries to init hikari conn pool. If I run database everything is ok. Can I substitute this w/ in memory database somehow? Or better yet, drop the DB connection altogether and use service layer mock? Sorry if the question is dumb, I have no experience with JVM ecosystem, would be glad to get any suggestions.
    a
    • 2
    • 1
  • e

    ESchouten

    05/16/2022, 8:48 PM
    Perhaps anyone at #server has interesting insights on this subject!
    a
    • 2
    • 2
  • d

    dave

    05/17/2022, 9:06 AM
    We're coming across this problem with LocalDynamoDB (the JAR of which still ships with a bundled Kotlin 1.3.72 and hence is basically incompatible with everything Kotlin if you want it in the same process!). Has anyone else worked around this - or even is there someone here who works for Amazon who can help to get it sorted? https://github.com/aws/aws-sdk-java-v2/issues/2487
    j
    d
    • 3
    • 2
  • b

    BingZi233

    05/17/2022, 11:31 PM
    Hello, I have a problem. In the code below, I try to set up a static directory. Unfortunately, I ran into a 404 error. I looked at the WIKI example, but nothing improved.
    p
    • 2
    • 2
  • k

    Kristian Nedrevold

    05/20/2022, 10:46 PM
    Hey, does anyone know how I can parse 2022-05-20T19:36:27Z with kotlinx-datetime?
    j
    r
    p
    • 4
    • 11
  • a

    Alexis Cala Martínez

    05/23/2022, 11:00 PM
    Team i am not sure, but is there any kind of info about kotlin for MS?
    😕 2
    ❓ 6
    b
    v
    +3
    • 6
    • 13
  • t

    Thanabodee Charoenpiriyakij

    05/31/2022, 11:10 AM
    Hi, all I’ve a java rpc library that take data as Map<String, Obect> and return as the same type. I try to convert it to data class to make code readable. I’m finding a solution to serialize a map to object and deserialize it. Currently I found that we can use json convert object to the json and deserialize to map. But it quite a bit tricky. 🫥 I also found that kotlinx serialization has properties data serialization but the limitation is it convert nested object to flat key. 😢 Does anyone found this similar issue? How do you solve it?
    r
    e
    j
    • 4
    • 9
  • i

    Iwan Aucamp

    06/02/2022, 3:31 PM
    Which is a better choice for kotlin, quarkus or micronaut?
    :ktor: 10
    c
    a
    +4
    • 7
    • 35
  • k

    kenkyee

    06/02/2022, 3:41 PM
    FWIW, I found reactive support a bit quirky w/ Quarkus/Hibernate/Panache...feels like hibernate reactive isn't really there yet.
    a
    t
    • 3
    • 5
  • a

    Andromadus Naruto

    06/07/2022, 5:27 AM
    Hi @everyone. I'm using the Komapper ORM for Kotlin and I can't seem to find a way to configure unique columns on a field via annotations. Can anyone with experience please help me with this? Thanks.
    p
    • 2
    • 1
  • d

    dleuck

    06/08/2022, 5:26 AM
    @Toshihiro Nakamura Are you using Komapper in any apps running in production? I really like the design of it, but I'm wondering if its been battle tested. We would be using it with Ktor and Postgres.
    t
    e
    e
    • 4
    • 5
  • a

    Andrzej Sawoniewicz

    06/09/2022, 2:56 PM
    Hi, anybody know why using @Validated on a Controller class in Spring could mess up with constructor injections? I simply get null values for all injected objects. The problem came out after migration to Kotlin from Java.
    :not-kotlin: 4
    m
    d
    • 3
    • 17
  • g

    Gopal S Akshintala

    06/14/2022, 1:46 PM
    Tech stack question: Does anyone know of examples of using Ktor for distributed systems? I am looking to implement asynchronous parallel processing, evaluating if Ktor is a right framework to start. I recently explored Spring batch which seems close to what I need, are there any similar use-cases solved with Ktor?
    p
    a
    • 3
    • 2
  • c

    Cody Mikol

    06/14/2022, 6:30 PM
    how do you enable the k2 compiler in gradle (groovy)?
    a
    l
    m
    • 4
    • 4
  • p

    Paul-Arthur Thiery

    06/15/2022, 1:35 PM
    Hi ! I've checked the docs for compiling Java and Kotlin together with Maven, and I've scrupulously copied the pom.xml setup, however I'm still get
    Unresolved Reference
    for every single import in my
    .kt
    files. Using the builtin Intellij compiler works fine however ! Is this a known issue ?
    l
    a
    • 3
    • 24
  • i

    IsaacMart

    06/17/2022, 4:51 AM
    Hello guys, Am using ktor and mongoDB as my backend for an android project. When inserting a document, the acknowledgement returns true, but when i get InsertedId, it returns null despite being inserted in the database
    :not-kotlin: 4
    🚔 1
    r
    • 2
    • 4
  • p

    Partho Paul

    06/21/2022, 5:13 AM
    Hi everyone, I’m using ktor and dynamodb for my backend project. I’m trying to fetch data from db using the below piece of code:
    getDynamoDbClient().use { ddb ->
                    return@use ddb.getItem(dbRequest)
                }
    Upon running this, I’m getting
    java.lang.IncompatibleClassChangeError: Found interface kotlin.time.TimeMark, but class was expected
    error. I’m doing it as it’s shown in https://github.com/awsdocs/aws-doc-sdk-examples/blob/main/kotlin/services/dynamodb/src/main/kotlin/com/kotlin/dynamodb/GetItem.kt. Am I doing anything wrong? Kotlin version: 1.7.0, Ktor version: 2.0.2, aws version: 0.16.0 TIA
    👀 2
    i
    l
    a
    • 4
    • 4
  • i

    itzik kasovitch

    06/27/2022, 8:14 AM
    Hi, In my application that is running on top of Ktor 1.6.4 I noticed that call.receiveText() returns a garbled string if the input text is in Japanese. I ruled out that it happens on the client side. Is there some configuration I forgot to do to make receiveText handle Japanese correctly?
    j
    c
    • 3
    • 3
  • v

    v79

    06/27/2022, 8:10 PM
    Would there be much interest in a #serverless channel? I've often wondered if Ktor could compile to Javascript to run on AWS Lambda...
    :yes: 2
    j
    m
    +4
    • 7
    • 24
  • a

    Alex Stelmachonak

    06/28/2022, 3:35 PM
    Hi all! Want to collect some ideas about the problem I have in Kotlin+Jackson space. I wanted to implement something like this:
    interface HttpResponseBody {
    	val asString: String
    	
    	inline fun <reified T : Any> asInstanceOf(format: BodyFormat): T =
            when (format) {
                BodyFormat.JSON -> jacksonObjectMapper().readValue(asString)
            }
    }
    so I can utilize the jackson-kotlin support of reified type parameters to not pass class instance to the deserialization method and be able to use it like this
    response.body.asInstanceOf<User>(BodyFormat.JSON)
    But
    reified
    only works in
    inline
    functions and I can't inline the function in interface. I was looking for not ugly way to workaround that and have similar implementation in place. So far I found two ways of doing this: 1. Convert
    HttpResponseBody
    to abstract class, so
    inline
    and
    reified
    are working. 2. Convert
    asInstanceOf
    method to the extension method of the
    HttpResponseBody
    interface. Both are working, but doesn't fit nicely with my other codebase (which I probably need to refactor), but I wanted to ask may be I am missing some other solutions?
    m
    d
    • 3
    • 5
Powered by Linen
Title
a

Alex Stelmachonak

06/28/2022, 3:35 PM
Hi all! Want to collect some ideas about the problem I have in Kotlin+Jackson space. I wanted to implement something like this:
interface HttpResponseBody {
	val asString: String
	
	inline fun <reified T : Any> asInstanceOf(format: BodyFormat): T =
        when (format) {
            BodyFormat.JSON -> jacksonObjectMapper().readValue(asString)
        }
}
so I can utilize the jackson-kotlin support of reified type parameters to not pass class instance to the deserialization method and be able to use it like this
response.body.asInstanceOf<User>(BodyFormat.JSON)
But
reified
only works in
inline
functions and I can't inline the function in interface. I was looking for not ugly way to workaround that and have similar implementation in place. So far I found two ways of doing this: 1. Convert
HttpResponseBody
to abstract class, so
inline
and
reified
are working. 2. Convert
asInstanceOf
method to the extension method of the
HttpResponseBody
interface. Both are working, but doesn't fit nicely with my other codebase (which I probably need to refactor), but I wanted to ask may be I am missing some other solutions?
m

mitch

06/28/2022, 9:50 PM
Hey @Alex Stelmachonak I'm curious of what others do as well but what I usually do is to define a non-inline function in the interface, and then declare an inline extension function on the interface. Something like this:
interface HttpResponseBody {
  fun <T> instanceOf(bodyFormat: BodyFormat, clazz: Class<T>): T
}

inline fun <reified T> HttpResponseBody.instanceOf(bodyFormat: BodyFormat) = instanceOf(bodyFormat, T::class.java)
Oh you had tried this already in your second approach.
a

Alex Stelmachonak

06/28/2022, 9:57 PM
Thanks! The issue here is that I can't just call method from interface from the extension function - jackson kotlin method
readValue
requires generic type to be
reified
, which is not possible. If I just do
T::class.java
it kind of works, but looses the benefits of Kotlin classes additional runtime data. I.e. I can't just use data class without extra
@JsonProperty
annotations.
I will put this aside for some time and will try to fix it in few days - want to have a fresh look at this
d

DALDEI

07/02/2022, 8:26 AM
use the same type function that jackson-kotlin uses, not T::class.java use instanceOf( bodyFormat , jacksonTypeRef<T>() )
View count: 7