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
squarelibraries
  • z

    Zac Sweers

    07/15/2022, 12:58 AM
    Did you import the reified extension?
    import com.squareup.moshi.adapter
    🤔 1
  • c

    Colton Idle

    07/15/2022, 1:00 AM
    Phew. Thanks Zac. I added that, then added
    @OptIn(ExperimentalStdlibApi::class)
    to my method. 🙏
  • j

    Javier

    07/22/2022, 10:54 AM
    Has anyone had problems with parallel tests and
    MockWebServer
    ?
    y
    7 replies · 2 participants
  • g

    galex

    07/24/2022, 4:26 PM
    Hello, I've got a question about
    okhttp
    😊 We're using
    okhttp
    with
    Retrofit
    and
    Apollo
    , and I'd like to get the full http request right before it is really being executed. I can get the
    Call.request()
    to get the request object but this one doesn't contain the headers we're adding through interceptors for example... Is there any extension to get the real request? Or am I correct to assume I can't use interceptors if I want to achieve this?
  • j

    jw

    07/24/2022, 4:33 PM
    An interceptor is the mechanism, ideally the last network interceptor
  • g

    galex

    07/24/2022, 4:54 PM
    Thanks, I'll check this again, but my issue is that interceptors receive the response before the parsing of the body response into its generic type (by retrofit or Apollo). Ideally I'd like to know the request succeeded and the response was correctly parsed into its generic type then log the request + response following some business logic we have
  • j

    jw

    07/24/2022, 5:01 PM
    Sounds like what you want is asymmetric then. For the request you want the last network interceptor. For the response the only real hook is a logging adapter or logging converter, although the converter doesn't see headers.
    👍 2
  • i

    itnoles

    07/24/2022, 11:54 PM
    <https://www.apollographql.com/docs/kotlin/advanced/interceptors-http#reusing-okhttp-interceptors-on-jvm-only-projects> this could help or not
  • x

    xxfast

    07/25/2022, 1:49 AM
    Hi all - is there a guide on how to setup SqlDelight on JVM? the guide here is only for a
    <http://JdbcSqliteDriver.IN|JdbcSqliteDriver.IN>_MEMORY
    , but I'm looking for something more permanent
  • j

    jw

    07/25/2022, 2:44 AM
    it's a standard jdbc string so you want
    jdbc:sqlite:/path/to/file.db
    for a persisted sqlite database
    ✅ 1
  • j

    jw

    07/25/2022, 2:44 AM
    https://github.com/JakeWharton/dodo/blob/e64a6d12afcadba674a726cce37a1dd20414bf06/src/main/kotlin/com/jakewharton/dodo/db.kt#L7
  • m

    MikeH

    07/26/2022, 3:05 PM
    Hey 👋 Does anyone have an example of how you could test a fragment/activity using paparazzi? Or is it only for tests on individual views?
  • s

    saket

    07/26/2022, 3:25 PM
    It's only for rendering views
  • l

    Lukasz Kalnik

    07/28/2022, 3:49 PM
    How can I parse with Moshi double nested dynamic objects? I can have different types of
    trigger
    in my JSON. Then, for
    trigger
    type
    SENSOR
    I can have (nested) different types of
    condition
    (examples see in thread 🧵:
    1 reply · 1 participant
  • j

    jw

    07/28/2022, 3:52 PM
    In general the strategy is to use a custom adapter which calls
    readJsonValue()
    that will give you a
    Map
    (for a JSON object) which you can query to determine the "shape" of the object. Then, you can delegate to the correct adapter which can parse that specific shape. So for your root object you would delegate to an adapter for a
    Time
    or
    Sensor
    object. Now the problem is fractal so you just repeat yourself. You register a custom adapter for
    Sensor
    which does the same thing (reads the json a "value" and inspects it) to create either an
    AlwaysCondition
    or a
    ThresholdCondition
    .
  • j

    jw

    07/28/2022, 3:54 PM
    Now, Moshi has a built-in type which will probably do both of these levels of shape-detetion for you: https://github.com/square/moshi/blob/master/moshi-adapters/src/main/java/com/squareup/moshi/adapters/PolymorphicJsonAdapterFactory.kt
  • j

    jw

    07/28/2022, 3:56 PM
    Your case seems simple where there's always a JSON key that acts as a discriminator whose value determines the shape and thus the type to deserialize. Its documentation should get you pretty far. You'll register it twice, once for
    Trigger
    and then once for
    Condition
    .
  • l

    Lukasz Kalnik

    07/28/2022, 3:59 PM
    Thank you! I registered a custom Adapter for both
    Trigger
    and
    Condition
    types with
    @ToJson
    and
    @FromJson
    function implementations. I then registered them both with Moshi using
    add()
    , but then the internal
    Condition
    object was serialized as plain string (with all the JSON symbols like
    {}
    etc. escaped with
    \
    ).
  • l

    Lukasz Kalnik

    07/28/2022, 4:00 PM
    I suppose PolymorphicJsonAdapterFactory will help with that?
  • j

    jw

    07/28/2022, 4:02 PM
    If you are delegating in a custom adapter you generally want to be using
    JsonWriter
    as a parameter which gives you access to write raw JSON (or to pass the
    JsonWriter
    along to a delegate adapter so it can). Perhaps you could look at the implementation of the polymorphic adapter to get some ideas. There's also some examples in the repository for custom adapter things.
  • l

    Lukasz Kalnik

    07/28/2022, 4:03 PM
    Thank you very much for such quick and comprehensive answers! 🙏
  • l

    Lukasz Kalnik

    07/29/2022, 8:57 AM
    Update: actually I now discovered the bug in my
    @ToJson
    implementation: I was using
    toJson()
    instead of
    toJsonValue()
    . That's why the serialized JSON was escaped like a plain string. It didn't have anything to do with nesting. But I will switch to a polymorphic adapter factory anyway, because then I won't have to implement from/to JSON functions myself and won't be able to make these kind of errors.
  • y

    yshrsmz

    08/02/2022, 9:46 AM
    Hi, is it possible to change Paparazzi's snapshots output directory? Readme says it "defaults to `src/test/snapshots`", but I can't find a way to change it. https://github.com/cashapp/paparazzi
    j
    j
    +1
    9 replies · 4 participants
  • l

    Lukasz Kalnik

    08/02/2022, 1:39 PM
    I'm using Retrofit's
    MoshiConverterFactory
    for my API calls, however it doesn't support sealed classes containing `object`s. I'm trying to generate adapters for the sealed class hierarchy using
    moshi-sealed
    , but I still get the error
    object Always cannot be serialized
    . Here the hierarchy:
    @Keep
    @JsonClass(generateAdapter = true, generator = "sealed:type")
    sealed class TriggerCondition(val type: String) : Serializable {
    
        @Keep
        @TypeLabel("ALWAYS")
        object Always : TriggerCondition("ALWAYS")
    
        @Keep
        @TypeLabel("NIGHT")
        object Night : TriggerCondition("NIGHT")
    
        @Keep
        @TypeLabel("LIGHT_SENSOR")
        @JsonClass(generateAdapter = true)
        data class LightSensor(
            val sensorInfo: SensorInfo,
        ) : TriggerCondition("LIGHT_SENSOR")
    }
    z
    24 replies · 2 participants
  • e

    Emirhan Emmez

    08/02/2022, 11:06 AM
    Hello, why is my interceptor not proceeding request?
    class TokenInterceptor @Inject constructor(
        private val preferencesRepository: PreferencesRepository,
        private val cognitoRepository: CognitoRepository
    ) : Interceptor {
        override fun intercept(chain: Interceptor.Chain): Response {
            return runBlocking {
                val request = chain.request().newBuilder().build()
    
                if (preferencesRepository.isTokenExpired()) {
                    cognitoRepository.login(
                        number = null,
                        password = null,
                        refreshToken = preferencesRepository.getRefreshToken(),
                        loginType = CognitoRepository.LoginType.RefreshToken
                    ).collect()
                }
    
                chain.proceed(request)
            }
        }
    }
    j
    j
    9 replies · 3 participants
  • s

    Stylianos Gakis

    08/04/2022, 9:55 AM
    Looking at the KotlinPoet documentation https://square.github.io/kotlinpoet/ I can’t seem to find how one would generate a function with a generic argument with an upper bound to some type, something like:
    fun <T : SomeType> foo(param: Bar<T>): Unit {
      asdf(myParam)
    }
    Is there some part of the docs which I am missing? If so I’d really appreciate any pointers.
    m
    4 replies · 2 participants
  • k

    KamilH

    08/05/2022, 5:43 PM
    When, approximately can we expect Melecule supporting native targets? JetBrains Compose 1.2 needs to be stable?
  • j

    jw

    08/05/2022, 5:43 PM
    Yes
  • j

    jw

    08/05/2022, 5:44 PM
    And it will only support the native targets they support which a few weeks ago seemed like only iOS, unfortunately
    l
    k
    +1
    10 replies · 4 participants
  • k

    KamilH

    08/05/2022, 6:31 PM
    Are you planning to release an alpha version of the molecule to get some early feedback? 🙂
Powered by Linen
Title
k

KamilH

08/05/2022, 6:31 PM
Are you planning to release an alpha version of the molecule to get some early feedback? 🙂
View count: 1