Robert Jaros
08/18/2021, 7:49 AMrunBlocking {}
?efemoney
08/18/2021, 10:41 AMvalue class
es as arguments. i’m seeing this exception (stacktrace in thread):
IllegalArgumentException: object is not an instance of declaring class
Dirk
08/21/2021, 7:52 PMNull return value from advice does not match primitive return type for: public abstract double <DTONAME>.<METHOD>()
Neil
09/09/2021, 10:19 AMnfrankel
09/12/2021, 9:01 PMviralshah
09/20/2021, 4:18 PMNick Halase
09/23/2021, 10:24 PMgotoOla
09/24/2021, 8:44 AM@Service
class MyClass(
myService: MyService, // autowired
helper: Helper = Helper("defaultValue") // just get default value but somebody could override this in e.g. tests
)
?Michael Strasser
09/29/2021, 1:05 AMBen Madore
10/06/2021, 3:33 PMsrc/main/kotlin/com/foo/Blah.java
src/main/kotlin/com/foo/bar/WebController.kt
WebController instantiates and uses a Blah. at compile time, no issues. when i start the app with gradle bootRun
- at runtime i get:
java.lang.NoClassDefFoundError: com/foo/Blah
i shouldn’t have to do anything special to make sure the java classes are on the classpath, right?Robert Jaros
10/10/2021, 6:24 AM500 Internal Server Error
when there is a problem with deserialization (e.g. missing key in the request data). When using jackson serialization with the same data the error is 400 Bad Request
. Can I somehow configure the returned error for kotlinx.serialization?thanksforallthefish
10/12/2021, 6:52 AMInt
. with String
you get an exception, I guess it might be the compiler unwrapping Int
to integer
(compared to Integer
), where null == 0
also in plain java.
your second example needs a bit of configuration of the kotlin module,
jacksonObjectMapper().registerModule(KotlinModule(nullIsSameAsDefault = true))
(moved we don’t spam uninterested people)Kilian Steenman
10/18/2021, 5:11 PMCountryCode
which converts a String to a CountryCode. If this value is not there or invalid it will return a 400 “InvalidParameter”. But if I make the value nullable, the value should just be null when it’s missing or invalid.
@RequestParam(value = "country") countryCode: CountryCode // Should throw an exception when invalid or missing
@RequestParam(value = "country") countryCode: CountryCode? // Should be null when invalid or missing
Is there a way to create separate converters for the nullable and non nullable implementations? (Probably not because it’s not actually a different type?)
By just returning null in the converter I will get:
Required request header 'country' for method parameter type CountryCode is present but converted to null
Which feels like its leaking some information to the outside world which they don’t need to know about.
I could make the param an Optional<CountryCode>
for the nullable case, map the message of the exception or do the mapping from String to CountryCode in the controller function. But those options all feel less nice. Is there a completely different solution I didn’t think of?Emil Kantis
10/19/2021, 5:59 PM@Cacheable
method. Since @Cacheable
is broken for suspend functions, I tried to do this with reactor-types for the specific method instead. Looks something like this:
@Cacheable("my-cache")
fun fetchThing(key: String): Mono<Thing> =
webClient.get("/thing/{key}", key)
.retrieve()
.bodyToMono()
Now, in the code where I use this. I want to bridge back into awesome realm of suspend (😉), so I do: restClient.fetchThing(key).awaitSingle()
. However, it seems that invoking awaitSingle()
twice on a Mono
created this way will actually cause the webrequest to fire again, instead of lazily returning the already existing result in the Mono
.. Does anyone know the proper way to get back to suspend functions after creating a Mono like this? Should I map the mono to a lazy mono of first result or something?thanksforallthefish
11/03/2021, 2:49 PMResult
and AOP
package com.example.demo
import org.aspectj.lang.ProceedingJoinPoint
import org.aspectj.lang.annotation.Around
import org.aspectj.lang.annotation.Aspect
import org.springframework.boot.autoconfigure.SpringBootApplication
import org.springframework.boot.runApplication
import org.springframework.stereotype.Component
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RequestParam
import org.springframework.web.bind.annotation.RestController
@SpringBootApplication
class DemoApplication
fun main(args: Array<String>) {
runApplication<DemoApplication>(*args)
}
@RestController
@RequestMapping("/test")
class TestController(val repository: TestRepository) {
@GetMapping
fun test(@RequestParam(defaultValue = "#{{}}") list: List<Int>) =
repository.getList(list)
.getOrElse { list }
}
@Component
class TestRepository {
fun getList(list: List<Int>): Result<List<Int>> = runCatching { throw RuntimeException("Error") }
}
@Aspect
@Component
open class MyOhMy {
@Around("within(com.example.demo..*Repository+)")
fun aspect(joinPoint: ProceedingJoinPoint): Any? =
joinPoint.runCatching {
proceed()
}.getOrThrow()
}
issue is that getOrThrow
in the aspect actually throws, while I would expect to return a Result<Failure
more in threadEmil Kantis
11/24/2021, 11:07 AMobject is not an instance of declaring class
when trying to use a @PathVariable
that is a value class.Jilles Soeters
11/24/2021, 4:37 PM@Service
component, some in models.kt. I’ve seen extensions.kt in other places… Wdyt?xii
11/25/2021, 4:59 PM@AssertTrue
in the data class, but I'm getting an unused function error (🧵 )Júlio Santos
12/07/2021, 7:10 PMLeonardo Borges
12/10/2021, 11:32 AMapplication.yaml
which is set like maxRetries: ${MAX_RETRIES:3}
where MAX_RETRIES
is set as an env var.
I'm using Spring to map the properties using @ConfigurationProperties
. This particular variable is UByte
and since it is kotlin, Spring can't map it.
Any clues how to convert it properly?Robert
12/13/2021, 7:19 AMPhilipp Mayer
12/15/2021, 3:51 PM@Configuration
class MyConfig {
@Bean
fun sendAnEmail(emailPublisher: EmailPubSubPublisher) = sendAnEmailLambdaVersion(emailPublisher)
}
fun sendAnEmailLambdaVersion(emailPublisher: EmailPubSubPublisher): (SomeEmail) -> Mono<String> =
{ email: SomeEmail -> emailPublisher.send(email) }
sure it works, but throwing @Bean
on the function directly would be ofc more elegant, but I’m currently making no progress in that direction.
Does anyone have any experience with that? Thanks! 🙂sdeleuze
12/28/2021, 2:03 PMkotlin-reflect
dependency from Spring Boot 3 applications and use a more lightweight Kotlin reflection alternative, I will share more on that as we make progress.xii
12/28/2021, 3:36 PMdany giguere
01/06/2022, 5:52 PMexistingUser.copy(username...
here :
package com.example.app.controllers
import com.example.app.models.User
import com.example.app.repositories.UserRepository
import org.springframework.http.HttpStatus
import org.springframework.http.ResponseEntity
import org.springframework.web.bind.annotation.*
import java.util.*
import javax.validation.Valid
@RestController
@RequestMapping("/api")
class UserController(private val userRepository: UserRepository) {
@PutMapping("/users/{id}")
fun updateUserById(@PathVariable(value = "id") userId: Long,
@Valid @RequestBody newUser: User): ResponseEntity<User> {
return userRepository.findById(userId).map { existingUser ->
val updatedUser: User = existingUser.copy(username = newUser.username)
ResponseEntity.ok().body(userRepository.save(updatedUser))
}.orElse(ResponseEntity.notFound().build())
}
I get this compiling error: Unresolved reference: copy
dany giguere
01/06/2022, 10:07 PMquiqua
01/08/2022, 2:43 PMCREATE TABLE elements (
id SERIAL PRIMARY KEY,
resource_id VARCHAR(50) UNIQUE DEFAULT uuid_generate_v4(),
name VARCHAR(100) NOT NULL
)
and a class like
@Entity
@Table(name = "elements")
data class Element(
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column
var id: Int?,
@Column
var resourceId: String?,
@Column
var name: String?
)
How can I only create new objects via val elem = Element(name="foo")
and let the rest be automatically created via JPA/Hibernate
Is that even possible in my case? Do I just need different constructors then?Sushruth Nagaraj
01/10/2022, 4:21 AMGoldcrest
01/12/2022, 7:52 AM@Scheduled
annotation with Reactive Spring + Webflux’s Flux.interval
method. Is this approach sane? Thanks in advance!jbnizet
01/13/2022, 2:39 PMfun run(vararg args: String?) {
(1..10).toFlux()
.flatMap({ this.get() }, 3)
.collectList()
.block()
?.forEach { println(it) }
}
private fun get(): Mono<String> {
return webClient.get()
.uri("/foo")
.retrieve()
.bodyToMono<String>()
}
jbnizet
01/13/2022, 2:39 PMfun run(vararg args: String?) {
(1..10).toFlux()
.flatMap({ this.get() }, 3)
.collectList()
.block()
?.forEach { println(it) }
}
private fun get(): Mono<String> {
return webClient.get()
.uri("/foo")
.retrieve()
.bodyToMono<String>()
}
withContext(<http://Dispatchers.IO|Dispatchers.IO>.limitedParallelism(3))
and by making each request block the current thread, but it defeats the purpose of using coroutines, doesn’t it?Szymon Jeziorski
01/13/2022, 6:07 PMawaitBody()
, awaitSingle()
awaitExchenge()
etc. to integrate Reactor reactive flow with kotlinx.coroutines.
Please read:
https://spring.io/blog/2019/04/12/going-reactive-with-spring-coroutines-and-kotlin-flow
https://github.com/Kotlin/kotlinx.coroutines/tree/master/reactive/kotlinx-coroutines-reactor
https://github.com/Kotlin/kotlinx.coroutines/tree/master/reactive/kotlinx-coroutines-reactivesdeleuze
01/13/2022, 8:11 PMjbnizet
01/13/2022, 8:46 PMfun run() {
runBlocking {
withContext(Dispatchers.IO.limitedParallelism(3)) {
(1..10).map {
async { get() }
}.forEach { println(it.await()) }
}
}
}
private fun get(): String {
val body = webClient.get()
.uri("/foo")
.retrieve()
.bodyToMono<String>()
.block()!!
return body
}
But replacing get() by this implementation sends all the requests at once:
private suspend fun get(): String {
return webClient.get()
.uri("/foo")
.retrieve()
.awaitBody()
}
sdeleuze
01/13/2022, 8:56 PMjbnizet
01/14/2022, 1:40 PMsdeleuze
01/14/2022, 5:03 PM