Code Monkey home page Code Monkey logo

kotlin-tutorials's Introduction

Kotlin Tutorials

This project is a collection of small and focused tutorials - each covering a single and well defined area of development in the Kotlin ecosystem. All the tutorials can be found on https://www.baeldung.com/kotlin

Building the project

To build the entire repository with only Unit Tests enabled run:

mvn clean install -Pdefault

or if we want to build the entire repository with Integration Tests enabled, we can do:

mvn clean install -Pintegration

This should not be needed often as we are usually concerned with a specific module.

Building a single module

To build a specific module run the command: mvn clean install in the module directory.

Working with the IDE

This repo contains a large number of modules. When you're working with an individual module, there's no need to import all of them (or build all of them) - you can simply import that particular module in either Eclipse or IntelliJ.

Running Tests

The command mvn clean install from within a module will run the unit tests in that module. For Spring modules this will also run the SpringContextTest if present.

To run the integration tests, use the command:

mvn clean install -Pintegration

kotlin-tutorials's People

Contributors

albertache1998 avatar alimate avatar anastasiosioannidis avatar asjad-j avatar behnamkhani-git avatar collaboratewithakash avatar dariusandz avatar davidmartinezbarua avatar diegotorrespy avatar edizor avatar eric-martin avatar fabiotadashi avatar gaetanopiazzolla avatar hangga avatar johna1331 avatar kanake10 avatar leocolman avatar lor6 avatar maibin avatar maiklins avatar maryarm avatar mona-mohamadinia avatar nappy29 avatar polomos avatar rcalago avatar sk1418 avatar sulion avatar tapankavasthi avatar theangrydev avatar vinaywadhwa avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

kotlin-tutorials's Issues

JacksonUnitTest.kt very fragile, hard/impossible to get working

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...

Kotlin Sealed Class is package level now

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

Guide to Spring Boot Testing

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"
        }
    }
}

Person entity default constructor

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?

Current implementation of LoggingResponseDecorator may log uninitialized headers

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.