kotlin

Moshi cannot parse nullable

一曲冷凌霜 提交于 2021-01-28 11:30:21
问题 Hello) Hope you can help me. Using kotlin (Retrofit2 + moshi) i getting data from "https://api.spacexdata.com/v3/launches" and parsing it. All is going fine (i getting attributes like: flight_number, mission_name), but some attributes have "null", like "mission_patch" - there are 111 objects. 109 of them have data at "mission_patch", 2 objects dont have it ("mission_patch":null). My problem: moshi cannot parse correctly attribute which contains null. if i using: data class SpaceXProperty( val

Java / Kotlin / Spring Boot. How can we automatically retrieve parameter values when an exception occurs?

半腔热情 提交于 2021-01-28 11:14:59
问题 Considering that we are using Kotlin , Spring Boot , annotations and other related libraries. If we have a situation in which our code throws an exception, how could we automatically retrieve the method parameters values in the moment of that exception? Can we do this using AOP, Spring Interceptors or other techniques? We would like to have this to enrich our error messages so we could replicate the errors from where they occurred. Please note that we are searching for a solution that we don

Multiple retrofit2 requests using Flowable in Kotlin

左心房为你撑大大i 提交于 2021-01-28 10:47:26
问题 In order to improve my skills in kotlin, Rx, Retrofit2 I've decided to do a demo project. The demo project consist to display posts in a recycler view then display details of the post in a detail activity. I've encountered difficulties displaying data coming from different api call: the user name, the title, the body of the post and the number of comments of the post. My problem is that I would like to do multiple request and then have all the data needed in order to display them in the

Multiple retrofit2 requests using Flowable in Kotlin

孤街浪徒 提交于 2021-01-28 10:42:12
问题 In order to improve my skills in kotlin, Rx, Retrofit2 I've decided to do a demo project. The demo project consist to display posts in a recycler view then display details of the post in a detail activity. I've encountered difficulties displaying data coming from different api call: the user name, the title, the body of the post and the number of comments of the post. My problem is that I would like to do multiple request and then have all the data needed in order to display them in the

Android RdioGroup clearCheck conflict with setOnCheckedChangeListener

时间秒杀一切 提交于 2021-01-28 10:34:47
问题 I'm trying to take an action when a radio button clicked: dataBinding.radioGroup.setOnCheckedChangeListener { radioGroup: RadioGroup, i: Int -> if( radioGroup.checkedRadioButtonId != -1){ checkAnswer(i) } } inside another function there is a clearCheck to clear radio button . the issue is that every time clearCheck is called, the listener setOnCheckedChangeListener also called. is there any way to run the listener to get run when a radio button is selected and not when it is cleared? 回答1: /**

Android RdioGroup clearCheck conflict with setOnCheckedChangeListener

本秂侑毒 提交于 2021-01-28 10:30:43
问题 I'm trying to take an action when a radio button clicked: dataBinding.radioGroup.setOnCheckedChangeListener { radioGroup: RadioGroup, i: Int -> if( radioGroup.checkedRadioButtonId != -1){ checkAnswer(i) } } inside another function there is a clearCheck to clear radio button . the issue is that every time clearCheck is called, the listener setOnCheckedChangeListener also called. is there any way to run the listener to get run when a radio button is selected and not when it is cleared? 回答1: /**

Get Currency symbol of only one character (e.g $,₹, etc) (Locale doesn't matter) android kotlin

不羁的心 提交于 2021-01-28 09:21:21
问题 i have currency code (e.g. USD,INR,etc...). I want to get symbols of only one letter of those codes (e.g $,₹, etc). i have tried to find many solutions like this but it doesn't works for me. i am using code as below var pound = Currency.getInstance("GBP"); var symbol = pound.getSymbol(); but it returns symbols like (Rs., US$, AU$, etc...). i want to get only one character symbol as mentioned above. i know that symbols are dependent on their locale but i want to get symbols independent from

Why can Kotlin high order functions have named arguments?

我是研究僧i 提交于 2021-01-28 09:20:42
问题 Let's take the following code snippet: class Foo { fun bar(baz: (x: String) -> Unit) { // ... } } It compiles correctly both in that way and with baz: (String) -> Unit (note that x: has been removed here) Why is it possible to name the first argument of baz function as x ? Can it be used in any way? 回答1: This is optional to provide extra meaning for callers of the bar method, to let them know what the the baz method they're passing in will receive as their parameter. It will show up in

KTor site not reachable

ⅰ亾dé卋堺 提交于 2021-01-28 09:02:18
问题 I want to make a simple http server using ktor. However, when I enter the site (127.0.0.1:8080 or 0.0.0.0:8080), it just isn't there. It doesn't print and doesn't respond. However if I use NanoHttpd instead of ktor, everything works fine. What is my issue? import io.ktor.application.call import io.ktor.http.ContentType import io.ktor.response.respondText import io.ktor.routing.get import io.ktor.routing.routing import io.ktor.server.engine.embeddedServer import io.ktor.server.netty.Netty fun

Handling hundreds of routes in Vert.x best practices

我是研究僧i 提交于 2021-01-28 08:43:32
问题 Please have a look at the piece of code below. Now suppose i'll have hundreds of entity like "person". How would you code such a thing to get it clean, concise, efficient, well structured ? Tx class HttpEntryPoint : CoroutineVerticle() { private suspend fun person(r: RoutingContext) { val res = vertx.eventBus().requestAwait<String>("/person/:id", "1").body() r.response().end(res) } override suspend fun start() { val router = Router.router(vertx) router.get("/person/:id").coroutineHandler {