baeldung / kotlin-tutorials Goto Github PK
View Code? Open in Web Editor NEWSupporting code for the tutorials on https://www.baeldung.com/kotlin
Home Page: https://www.baeldung.com/kotlin
License: MIT License
Supporting code for the tutorials on https://www.baeldung.com/kotlin
Home Page: https://www.baeldung.com/kotlin
License: MIT License
The Kotlin Flow concept is intended to return a reference that notifies observers of changes to its value (which may be a list/collection) but here it is used as a replacement for list. It will kind of work but the way to return a list as flow is Flow<List<T>>
.
During instantiation of the LoggingResponseDecorator
, you are logging the headers of the response.
At that point the headers may not be initialized or fully committed. Besides, if I wanted to log the status code of the response, that would also be undefined at that stage. I have only tested this on the Java version of this code, but invoking the beforeCommit
delegate method worked for me:
public LoggingResponseDecorator(ServerHttpResponse delegate) {
super(delegate);
beforeCommit(() -> Mono.fromRunnable(() -> {
if (log.isDebugEnabled()) {
log.debug("{} {}", getStatusCode(), getHeaders());
}
}));
}
Sorry to create an issue of this, but the blog entry has the comments disabled.
Hello,
I see such warning Possibly blocking call in non-blocking context could lead to thread starvation on that line:
Every example on the internet contains such a logic. I wonder is it ok?
Reported in FasterXML/jackson-module-kotlin#437
I have been trying to reproduce examples in https://github.com/Baeldung/kotlin-tutorials/blob/master/kotlin-libraries-2/src/test/kotlin/com/baeldung/kotlin/jackson/JacksonUnitTest.kt
In particular, when compiling under Gradle/IntelliJ the Kotlin compiler rejects the syntax used
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
import com.fasterxml.jackson.module.kotlin.readValue
import com.fasterxml.jackson.databind.ObjectMapper
import com.fasterxml.jackson.module.kotlin.KotlinModule
. . .
val mapper = jacksonObjectMapper()
. . .
data class KmsCmkSecret(val cmkIdentifier: String, val dataKeyCiphertext: String)
. . .
val kmsCmkSecret1 = mapper.readValue<KmsCmkSecret>(secretJson)
val kmsCmkSecret2: KmsCmkSecret = mapper.readValue(secretJson)
kmsCmkSecret1
e: /Users/ekolotyluk/dev/crypto/common/src/main/kotlin/com/fispan/crypto/Aws.kt: (87, 35): None of the following functions can be called with the arguments supplied:
public inline fun <reified T> ObjectMapper.readValue(jp: JsonParser): TypeVariable(T) defined in com.fasterxml.jackson.module.kotlin
public inline fun <reified T> ObjectMapper.readValue(src: File): TypeVariable(T) defined in com.fasterxml.jackson.module.kotlin
public inline fun <reified T> ObjectMapper.readValue(src: InputStream): TypeVariable(T) defined in com.fasterxml.jackson.module.kotlin
public inline fun <reified T> ObjectMapper.readValue(src: Reader): TypeVariable(T) defined in com.fasterxml.jackson.module.kotlin
public inline fun <reified T> ObjectMapper.readValue(src: URL): TypeVariable(T) defined in com.fasterxml.jackson.module.kotlin
public inline fun <reified T> ObjectMapper.readValue(src: ByteArray): TypeVariable(T) defined in com.fasterxml.jackson.module.kotlin
public inline fun <reified T> ObjectMapper.readValue(content: String): TypeVariable(T) defined in com.fasterxml.jackson.module.kotlin
kmsCmkSecret2
e: /Users/ekolotyluk/dev/crypto/common/src/main/kotlin/com/fispan/crypto/Aws.kt: (88, 51): None of the following functions can be called with the arguments supplied:
public inline fun <reified T> ObjectMapper.readValue(jp: JsonParser): TypeVariable(T) defined in com.fasterxml.jackson.module.kotlin
public inline fun <reified T> ObjectMapper.readValue(src: File): TypeVariable(T) defined in com.fasterxml.jackson.module.kotlin
public inline fun <reified T> ObjectMapper.readValue(src: InputStream): TypeVariable(T) defined in com.fasterxml.jackson.module.kotlin
public inline fun <reified T> ObjectMapper.readValue(src: Reader): TypeVariable(T) defined in com.fasterxml.jackson.module.kotlin
public inline fun <reified T> ObjectMapper.readValue(src: URL): TypeVariable(T) defined in com.fasterxml.jackson.module.kotlin
public inline fun <reified T> ObjectMapper.readValue(src: ByteArray): TypeVariable(T) defined in com.fasterxml.jackson.module.kotlin
public inline fun <reified T> ObjectMapper.readValue(content: String): TypeVariable(T) defined in com.fasterxml.jackson.module.kotlin
Interestingly enough, in my code if I use
val kmsCmkSecret = mapper.readValue(secretJson, KmsCmkSecret::class.java)
this does not fail. In my build.gradle I am using
implementation("com.fasterxml.jackson.module:jackson-module-kotlin:latest.release")
I am using kotlin_version = "1.5.0-RC"
I've already wasted many hours fussing around with this, and this is very frustrating because the experience does not at all follow the simplicity of the examples. It seems the entire mechanism is very fragile and unpredictable... Having used Jackson for many years with success, I am astonished at this difficulty...
As an aside, I have completely given up on Kotlin Serialization, as it is even more pathological...
I may be reporting this in the wrong place, but it's where I started...
I see that in your example for JPA the person object is created using an ID of 0. I thought that with the jpa plugin we can create person using no-arg constructor Person() and then set the other properties except for ID. Please clarify if providing default ID's at object creation time is the only way to work with Kotlin & JPA?
Hey, I think this line is wrong as Kotlin allows for package-level inheritance now.
The compiler guarantees that only classes defined in the same source file as the sealed class are able to inherit from it
A sample class which uses constructor injection of the config should be provided to show how to use it
Hi Team,
May you please advise which license governs the kotlin-tutorials repo/project?
Thanks,
Radi
Hey @SmartyAnsh,
Thanks for the great article about Spring Boot Testing. I am working with gradle / kotlin setup and could not get your test setup working. I always got the error:
kotlin.UninitializedPropertyAccessException: lateinit property mockMvc has not been initialized
I don't know if this is just gradle specific, but in order to get kotest / funspec working with spring boot, I had to add:
override fun extensions() = listOf(io.kotest.extensions.spring.SpringExtension)
to my test. Than everything worked. Here is my demo controller test as an example:
@WebMvcTest
@ContextConfiguration
class DemoControllerTest : FunSpec() {
override fun extensions() = listOf(io.kotest.extensions.spring.SpringExtension)
@Autowired
private lateinit var mockMvc: MockMvc
init {
test("index") {
mockMvc.get("/hello").andReturn().response.contentAsString shouldBe "hello"
}
}
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.