r/java • • Dec 26 '25

Which lesser known libraries saved your butt this year?

It's holiday time, the sub is pretty dead, so let's stir the pot a little bit.

Most of this sub is probably well acquanted with likes of AssertJ, Guava, Vavr, Jackson, or JSpecify - we use them, we love them, but the ecosystem has more to offer.

Post lesser known Java libraries or tools that you rave about, are interesting, useful, or have saved your butt this year. Self promotion within reason is okay

207 Upvotes

68 comments sorted by

View all comments

102

u/TomKavees Dec 26 '25

I'll start:

  • JsonUnit - set of unit test assertions/matchers that allows comparing structure of json documents as easily as assertThat( actual ).asInstanceOf(JsonAssertions.JSON).isEqualTo( "{...}" );. Not a rocket surgery, but makes testing suck less
  • JStachio - annotation processor that takes in {{Mustache}} templates and generates a dependency-free renderer code. The day we started using it, it "found" a bunch of errors in our templates like missing/extra parameter that previous renderer silently ignored. Good dev experience, to the point, hasn't let me down yet
  • valueclasses - it may not be rocket surgery, but as somebody working in a domain that is very Stringly (e.g. location code vs location name) and longly typed (e.g. customer id vs order id vs location id), the use of custom value-based classes to leverage the compiler to do basic sanity checking has saved my butt over the last decade more times than i am willing to admit. Having a convenient point to do data normalization is also a plus
  • mvnd - the tl;dr is that if you work with multi-module maven projects, it will speed up your (re-)builds even more than regular multi-threaded build at the cost of adding one character to the command line. In one of projects i worked with (~60 modules, most really tiny, but with complex web of dependencies) the mvn -T2.0C ... achieved a speedup of ~43%, and mvnd ... achieved a speedup of ~55% over single-threaded build. It ain't magic though, single module builds see little speedup.

What are yours?

23

u/_predator_ Dec 26 '25

+1 on mvnd and +100 on JsonUnit.

Combined with text blocks the latter has completely transformed how I write a lot of tests. I love being able to see what the actual response of my endpoints look like right there in the test. Helps tremendously also to detect subtle unintended changes. The placeholders and matchers are handy for dynamic content. The diffs it gives on assertion failures make it super easy to spot where the problem is.

Great example of how something so seemingly simple can make such a huge difference.

13

u/gaelfr38 Dec 26 '25

I don't get what valueclasses (the library, not the concept) brings versus a regular record holding a single attribute. I mean I don't need the library to do the same. It just brings an interface, right? Or am I missing something?

(Don't get me wrong, I love the idea of using value classes to benefit from type safety)

7

u/TomKavees Dec 26 '25 edited Dec 27 '25

In ye olde days of 1.8 it brought a bunch of utility for both value-based classes and regular domain classes - for example the BaseObject class that implemented reflection-based equals/hashCode/toString, which has since been moved to the legacy package.

Nowadays, with records, it indeed boils down to having an uniform interface to extract inner value and have a bunch of utility methods for string-based data (isEmpty/isBlank... you know the drill).

Besides the main shtick, i'm using these value-based classes(records) to do some data normalization in the consturctor - it obviously depends on particular kind of data, but it's usually an equivalent of trimToEmpty() + toUpperCase()

I included it on the list mostly for the idea behind it, not the amount of code it provides πŸ˜‰

5

u/gaelfr38 Dec 26 '25

Thanks, makes sense. Just wanted to be sure I didn't miss something :)

2

u/Medical_Vehicle_6788 Jan 05 '26

I wish this practice gets popular sooner in Java, many times I have to make devs understand how easy it’s to break a codebase that just depends on primitive and string alone. I worked with refined types library in scala, I was amazed how well we can define value objects. Incase if anyone is interested in refined types, https://rockthejvm.com/articles/refined-types-in-scala

1

u/Emma_S772 Dec 28 '25

MockMvc allow you to do the same as the first one if you already are testing with it

0

u/Beemeowmeow Dec 27 '25

Saving this for ref