Spring Data MongoDB MappingInstantiationException

Polymorphic fields with MongoDB and Spring Data

Depending on your needs using polymorphism might benefit different aspects of the project. For example, having a limited class hierarchy might make your code cleaner and more expressive in contrast to a single class having nullable fields or a type label. And it only seems natural to use it with document-oriented databases like MongoDB. But if you want to have a document with polymorphic fields using MongoDB and Spring Data you might face an exception similar to this: MappingInstantiationException: Failed to instantiate ...FieldType using constructor NO_CONSTRUCTOR with arguments. Let’s see why this happens and how to fix that issue properly.

Continue reading
WirePlumber high CPU usage fix

WirePlumber high CPU usage fix

I have Fedora 36 installed on my laptop. Recently I’ve been using it a lot with a Bluetooth headset and noticed that sometimes WirePlumber creates high CPU usage. Turns out it was happening when the system was switching the Bluetooth profile for the headset from HSP to A2DP and backwards. There is a fix for that issue, but it is not yet available in Fedora’s repos. If you’re having the same issue, here’s how to fix it.

Continue reading
reduce Java docker image size

How to reduce Java docker image size

If you’ve been using Java for a while, you might have noticed that starting with Java 11, Java Runtime Environment (JRE) doesn’t have a separate distribution anymore, it is only distributed as a part of Java Development Kit (JDK). As a result of this change, many official Docker images don’t offer a JRE-only image, e.g.: official openjdk images, Amazon corretto images. In my case using such an image was resulting in an app image of 414MB, where the app itself was only taking around 60MB. What a waste of space!

But fear not, as I’m going to show you how to reduce Java docker image size dramatically.

Continue reading