Spring Security provides a lot of convenience to develop secure web applications.
However, it relies strongly on a SecurityContext
stored in a thread-local (inside the SecurityContextHolder
class).
If not mitigated, this causes issues in multi-threaded contexts. When using Kotlin Coroutines, there is an additional
abstraction layer where you don’t really know (and don’t want to know) on which thread(s) your code will be running.
Luckily, there is a relatively easy solution!
Continue reading →
How would you like to use your favorite backend language to develop frontend?
In this blogpost I’ll show you how to compile a small kotlin example to WebAssembly and how to run the output in your browser.
Continue reading →
When code evolves we usually deprecate old code.
Sometimes we come across deprecations without any hints with what to replace it with.
Kotlin has a solution for this by allowing you to specify a replace instruction.
For example, we created have an old REST client.
Continue reading →
Kotlin data classes and annotations go really well together, but it is easy to mess it up.
Continue reading →
When dealing with Maps in Kotlin, sometimes we’re only interested in entries for which the value is not null
.
Although the Kotlin Standard Library contains a filterValues
function that seems to be appropriate, this function
does not do any type conversions, resulting in a Map
which won’t contain null
values,
but is still a Map with values of a nullable type according to the compiler. There is a feature request
for the JetBrains team to add this functionality, but for now it has not been implemented (yet?).
Continue reading →
If you write lots of Kotlin code you might have noticed that it is annoying to write the named parameters when calling functions or when creating a new instance of class.
Continue reading →
The Kotlin standard library contains a lot of helper functions on top of the Java standard library for our convenience.
Some of those functions help us in converting between different data types.
For example, the String.toInt()
function converts a number formatted as String
to its Int
representation.
But how do we accomplish the same with a Char
? Spoiler alert: NOT by using Char.toInt()
, but by using Char.digitToInt()
!
Continue reading →
Functions defined in Kotlin companion objects are often seen as the 'equivalent' of static methods in Java.
Although there are some similarities, there are also some caveats you should be aware of.
For example, how to use method references (or, to be pedantic: function references) to refer to functions
defined in a companion object.
Continue reading →
In this post I suggest a way to publish your backend API typings as an NPM package. Frontend projects using can then depend on these typings to gain compile time type safety and code completion when using Typescript.
It’s quite common in a microservice style architecture to provide a type-safe client library that other services can use to communicate with your service. This can be package with a Retrofit client published to nexus by the maintainer of the service. Some projects might also generate that code from a OpenAPI spec or a gRPC proto file.
However, when we expose some of these APIs to the frontend, we lose the types. In this post I suggest a way to publish your backend API types as an NPM package. The frontend can then depend on these typings. Using typescript you now have compile time type safety and code completion. To see a sneak peak, scroll to the end :).
Continue reading →
Micronaut makes it possible to easily configure your application using the provided mechanisms based on Spring and Grails.
This blog demonstrates how to configure a Kotlin based Micronaut application using Micronaut version 1.0.0.RC1.
First we create a Micronaut application featuring Kotlin:
After that we create our DemoController:
Continue reading →