why do you have an explicit `IntDeserializer()`? m...
# ktor
k
why do you have an explicit
IntDeserializer()
? maybe try removing that line, gson can deserialize Ints automatically.
t
It doesn't deserialize empty string for me, eg sending
ageGroupId:""
gives me
NumberFormatException: empty String
which I wanted to handle explicitly. Is there a way to handle that without adapter
Adapter is not resolving the issue for me either
k
you can't catch the exception in your adaptor?
like this:
t
Yes I am doing something like that but the adapter doesn’t seem to be called, so it’s still using the default deserializer
k
ok, so you just need to figure out how to properly register the adaptor. did you try
registerTypeAdapterFactory(...)
?
or at the bottom of the stackoverflow, maybe you need something like:
Copy code
registerTypeAdapter(java.lang.Integer::class.java, adapter)
t
Yes I am doing it like this:
Copy code
install(ContentNegotiation){
                register(ContentType.Application.Json, GsonConverter(GsonBuilder().apply {
                    setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES)

                    registerTypeAdapter(DateTime::class.java, DateTimeDeserializer())
                    registerTypeAdapter(Int::class.java, IntDeserializer())
                }.create()))
            }
k
maybe you need
java.lang.Integer::class.java
instead?
t
Hmm.. I’d try that. Thanks
k
or try the Factory method like in the stackoverflow?
t
java.lang.Integer::class.java
works fine thanks
Is that because gson doesn't recognize kotlin
Int
or what?
k
yeah, that's my guess