Java Records Unleashed: Validation Best Practices

preview_player
Показать описание
Simplifying RESTful Web Service Constraints in Java

In this episode of 'Tales from the Jar Side,' Ken Kousen guides Java developers through the process of simplifying constraints when interacting with a RESTful web service. Using a text-to-speech service example, Ken demonstrates four steps to enforce input restrictions programmatically. He covers using Java records, defining constants and enums, utilizing compact constructors for validation and transformation, and applying Bean Validation annotations. The episode also includes practical coding examples and a final test to ensure proper service utilization. All code is available in the accompanying GitHub repository.

00:00 Why do you we need to do this?
02:40 A basic request class
03:30 Defining constants
03:56 Adding enums
06:13 Overloaded constructors
07:44 Compact constructors
09:16 Bean Validation
11:17 Adding the validation dependency
12:01 Bean Validation Annotations
13:50 Testing
15:14 What have we learned?
16:41 Generating audio from text
Рекомендации по теме
Комментарии
Автор

Great content, as usual - and loving the practical examples with OpenAI. I'll keep following you on your journey, while you help us with ours!

antonindejesus
Автор

Thank you very much for this and all other your videos. I've just recently opened your channel - accidently came across your old presentation on Devoxx at first. Your style and presenting are amasing)
One of the best mentors ever!

michaelm
Автор

Great video! One question, did you choose to use Strings to represent the model type instead of using an Enum, like you did with the Voice or ResponseFormat, primarily to demonstrate the @Pattern validation method? Or was there some other reason why you preferred a String over an Enum?

zombi
Автор

I'm trying to understand functional programming and it seems that applicative functor are used for validation as well. what is your opinion about that?

Savatore
Автор

Why not model the inputs with sealed types instead of enums? I see that you are using gson so is it a restriction from that?

Mig