Coding

Why you should use Lombok

Posted on by  
Jacob van Lingen

It’s the year 2023. JDriven colleagues have gathered to discuss the new trends and deprecations of our work to put on the latest TechRadar. Once everybody is seated, everyone contributes their latest opinions. Very soon discussions run high. Lombok is dropped at the table of discussion as well. After some debate, it is decided. Lombok is put on HOLD!

Continue reading →

Spicy Spring: Splitting Configuration and make Properties immutable

Posted on by  
Willem Cheizoo

A Spring Boot application typically consists of several components handling the business functionality and probably some configuration to configure all these components. This configuration consists of defining some properties, setting up some beans with the right conditions and dependencies and wrapping it all together into a class structure. Nevertheless, the configuration of our Spring Boot application is also code. Let’s threat is as code.

In this blog we will se how we can improve our Spring Boot Configuration by splitting up the configuration from the properties and how this effects the design principles.

Continue reading →

Beginners guide to lambdas

Posted on by  
Ties van de Ven

Lamda expressions were introduced in Java 8 and have been around for a while. They are in my opinion one of the better features of Java 8, allowing for a more functional approach to writing code, and thus enabling most of the java 8 features. So let’s take a closer look at lambda’s and see what they are, how to reason about them, and why they are a good addition.

Continue reading →

Pragmatic explanation of Monads, the ‘short short version’

Posted on by  
Justus Brugman

This is a blog post that tries to give a pragmatic explanation about what a monad is, and what problem it tries to solve. This post is written by Ties van de Ven and Justus Brugman.

When I tried to learn about functional programming, I found myself lost in new words and jargon, I did not know about. Suddenly my vocabulary needed to be extended with terms like Monads, Monoids, Composable, Functors and so on. When trying to understand these terms, it became clear that I found it hard to understand what a monad is.

Continue reading →

Customising form validation in Javalin using Valiktor

Posted on by  
Justus Brugman

Since about a month I’m developing some microservices using Javalin, a small, simple and lightweight web-framework that started as a fork from SparkJava. By now it’s a ground-up rewrite, influenced by the Javascript framework koa.js. Don’t let the stuff like Either scare you, we use the Arrow library to make our life a bit more easy :)

When requesting user input from a form, it’s evident that we need to validate our input. Javalin has its own way of doing so (from the docs):

Continue reading →

Effectively use MapStruct and Lombok's builder

Posted on by  
Willem Cheizoo

Since MapStruct version 1.3.0.Final is out, we are able to better integrate with Lombok Builder pattern. MapStruct is a library that takes away a lot of boilerplate code for mapping between POJO’s. With MapStruct there is no need for implementing the real mapping itself.

With Lombok we can use a Builder pattern and mark an object as a Value(Object). It will result in an immutable object. This blog post shows how we can use MapStruct to use the Builder pattern of Lombok.

Continue reading →

Awesome Asciidoctor: Collapsible Content

Posted on by  
Hubert Klein Ikkink

Since Asciidoctor 2.0.0 we can add the collapsible option to an example block. When the markup is generated to HTML we get a HTML details and summary section. The content of the example block is collapsed (default behaviour because it is in a details section) and a clickable text is available to open the collapsed block (the summary section), so we can see the actual content. The text we can click on is by default Details, but we can change that by setting the title of the example block. Then the title is used as the text to click on to open the collapsed content.

Continue reading →

Awesome Asciidoctor: Help On Syntax As HTML

Posted on by  
Hubert Klein Ikkink

With the release of Asciidoctor 2.0.0 we get nice help on the basic syntax of Asciidoc with the command-line option --help syntax. This gives us samples of the syntax in Asciidoc markup. As mentioned by Dan Allen on Twitter we can pipe the syntax sample to Asciidoctor itself to get a HTML page:

Continue reading →

Micronaut Mastery: Parse String Value With Kb/Mb/Gb To Number

Posted on by  
Hubert Klein Ikkink

Micronaut can convert String values defined as a number followed by (case-insensitive) KB/MB/GB to a number value in certain cases. The conversion service in Micronaut supports the @ReadableBytes annotation that we can apply to a method parameter. Micronaut will then parse the String value and convert it to a number. The value 1Kb is converted to 1024. We can use this for example in a configuration class or path variable in a controller.

Continue reading →

Micronaut Mastery: Binding Request Parameters To POJO

Posted on by  
Hubert Klein Ikkink

Micronaut supports the RFC-6570 URI template specification to define URI variables in a path definition. The path definition can be a value of the @Controller annotation or any of the routing annotations for example @Get or @Post. We can define a path variable as {?binding*} to support binding of request parameters to all properties of an object type that is defined as method argument with the name binding. We can even use the Bean Validation API (JSR380) to validate the values of the request parameters if we add an implementation of this API to our class path.

Continue reading →

Groovy Goodness: Use Expanded Variables in SQL GString Query

Posted on by  
Hubert Klein Ikkink

Working with SQL database from Groovy code is very easy using the groovy.sql.Sql class. The class has several methods to execute a SQL query, but we have to take special care if we use methods from Sql that take a GString argument. Groovy will extract all variable expressions and use them as values for placeholders in a PreparedStatement constructed from the SQL query. If we have variable expressions that should not be extracted as parameters for a PreparedStatement we must use the Sql.expand method. This method will make the variable expression a groovy.sql.ExpandedVariable object. This object is not used as parameter for a PreparedStatement query, but the value is evaluated as GString variable expression.

Continue reading →

shadow-left