This blog post describes a vite plugin that can export static react router routes into a text file, one route per line, that can be easily parsed in a Java servlet to make it possible to reload the react router paths. Continue reading Export react-router routes for use in Java servlet
Category Archives: java programming
Build Java records with builders
When writing Java record withers what and when I discovered that the Java beans with builders resulting from Build beans better with builders could have their boiler plate code size reduced to half, if they were turned into records instead of beans.
This is the story of switching my Java beans to records and how that worked with jackson to build JSON objects from records and parse JSON objects into records. Continue reading Build Java records with builders
Java record withers what and when
This blog post is the result of searching the internet to find out what Java records with “withers” will look like and in what version of Java records with withers will arrive.
In addition, while trying to figure out Java withers, I discovered that reforming my current beans with builders into records with builders, I could throw away half the boiler plate code. Continue reading Java record withers what and when
Build beans better with builders
Edit: I no longer use beans with builders, I Build Java records with builders
Builders provide a nice, if verbose, way to create immutable java beans.
The upsides are a nice syntax for creating immutable beans, and a way to provide copy-on-write behaviour for immutable objects.
The downsides are the need for verbose boilerplate code, approximately doubling the code size of the bean source files, and the overhead of one extra object created and then left for garbage collection, for each created bean.
Chaining Optionals using flatMap and map
The blog post How I learnt to like Optional shows an example of how to chain Optional values safely, using Optional.orElse() to provide empty objects for the next level in the chain.
This blog post uses Optional.flatMap() and Optional.map(), to achieve the same thing, without having to create the empty objects, and without doing any evaluation for empty objects.
How I learnt to like Optional
I used to see Optional<Something> as a completely useless addition to Java, adding to the bloat of Java without being any clearer than checking if a reference is null.
I have changed my mind, and now think Optional<> can be useful in making code simpler, easier to understand, and more robust.
The reason I changed my mind, was the usefulness of Optional.orElseThrow() when having to traverse deeply nested data structures in Java code.
Composing applications with karaf features
I create web applications by first creating a set of OSGi bundles that form the building blocks of the application, and then use karaf features to pull the building blocks together to create complete applications that run inside apache karaf.
How to get test coverage back in sonarcloud maven builds
I use travis-ci to build my github projects and use sonarcloud to do analysis of the builds.
In the start of January 2020, the test coverage percentage on all sonarcloud projects suddenly dropped to 0%.
This blog post explains why coverage percentage dropped to 0% and how to get the test coverage back in the sonarcloud reports.
Continue reading How to get test coverage back in sonarcloud maven builds
Simplified REST APIs from karaf using Jersey
I have written the Java class JerseyServlet which is intended as a base class for DS (Declarative Services) components providing Servlet services to the OSGi web whiteboard.
The JerseyServlet simplifies the approach outlined in Use Jersey to provide REST APIs from karaf applications.
Continue reading Simplified REST APIs from karaf using Jersey