Scrivio Interview library
LeadershipPrincipal6 min read · updated 12 November 2026

Bean Validation has been part of Java for many years and is now Jakarta Validation. How do you judge whether to keep relying on such standards or adopt newer approaches, for example validation generated from schemas?

I judge it by how the company manages its API contracts. Standards such as Jakarta Validation give long-term stability, many implementations and wide tool support, while validation generated from schemas keeps the API and the code in sync automatically. They are not rivals: the best setup is often DTOs generated from an OpenAPI or JSON schema that carry Bean Validation annotations. What I would avoid is a custom in-house validation framework that duplicates what the standard already does.

Background to this question

Every few years a new approach promises to replace something we have used for a long time. With validation, the question is whether to keep annotating Java classes with a fifteen-year-old standard or to let a schema, an OpenAPI document or JSON Schema, drive validation instead. A senior engineer has to decide this for many teams and for years ahead, so the reasoning matters more than the fashion. In this answer, we will look at what a long-lived standard really gives us, what schema-generated validation gives us, how the two combine, how the company's contract process decides the choice, and why custom frameworks are usually the worst option.

1What a Long-Lived Standard Gives Us

Bean Validation started as JSR 303 in 2009 and is now Jakarta Validation. Over that time the annotations have barely changed: @NotNull, @Size and @Pattern mean the same thing today as they did then. That stability is a feature. Code written ten years ago still validates the same way, and the knowledge transfers from team to team and company to company.

A standard also brings an ecosystem. Spring MVC, JPA, Hibernate, Quarkus, Micronaut, Jackson-based tools and OpenAPI documentation generators all understand the same annotations. When we add @Size(max = 100) to a DTO, the springdoc tool shows maxLength: 100 in the generated API documentation without any extra work. The move from javax to jakarta was the one big migration in that history, and even that was mostly a package rename that tools automated.

2What Schema-Generated Validation Gives Us

In a contract-first approach, the API is designed as a schema before code is written: an OpenAPI document, a JSON Schema or a Protobuf definition. The schema is reviewed with the consumers, and code is generated from it for both sides. The benefit is that the contract and the implementation cannot drift: if the schema says maxLength 100, the server DTO and the client model both get it on the next build.

The costs are real too. Generated code needs a build step, generators have quirks and version upgrades, and some rules are hard to express in a schema, such as an end date after a start date. Teams also need the discipline to change the schema first, never the generated code.

Annotations, schema generation, or both
AspectHand-written annotationsSchema-generatedGenerated DTOs with annotations
Source of truthJava codethe schemathe schema
Drift between API and codepossiblepreventedprevented
Runtime validationBean Validationgenerated or schema validatorBean Validation
Cross-field and custom rulescustom constraintshardcustom constraints on top
Tooling and skillseverywheregenerator-specificboth

3Using Both Together

The two approaches meet nicely in the middle. The common OpenAPI generators for Java can emit DTOs with Jakarta Validation annotations taken from the schema's required, minLength, maxLength, pattern and minimum fields. At runtime, Spring validates them with Hibernate Validator exactly as if we had written them by hand.

Java
# openapi.yaml
PlaceOrder:
type: object
required: [productId, quantity]
properties:
productId: { type: integer, format: int64 }
quantity: { type: integer, minimum: 1, maximum: 99 }
// generated (shape shown; exact output depends on the generator and its options)
public class PlaceOrder {
@NotNull private Long productId;
@NotNull @Min(1) @Max(99) private Integer quantity;
}

So we keep the standard's runtime, tools and skills, and we gain the schema's single source of truth. The rules the schema cannot express, such as cross-field checks, are added as custom Bean Validation constraints or in the service, which is where they would live anyway.

4Choosing by How Contracts Are Managed

The deciding factor is the company's contract process, not the technology. If APIs are designed contract-first, reviewed as OpenAPI documents and shared with many consumers, generation is the natural fit and hand-written annotations would create a second source of truth. If APIs are code-first, where teams write controllers and publish documentation generated from code, then hand-written annotations are the source of truth, and adding generators would invert the workflow for little gain.

Many companies have both: public and partner APIs designed contract-first, internal APIs built code-first. Then the guideline can say exactly that, per kind of API, rather than forcing one process on everyone. What I would insist on in both cases is that the published schema and the running validation are checked against each other in the build, for example with contract tests.

Step throughDeciding the validation approach
  1. Are APIs designed contract-first?
    YesGenerate DTOs with annotationsNoHand-write annotations in code
  2. Add custom constraints for cross-field rulesstandard Bean Validation
  3. Check schema and behaviour in contract tests
  4. Does someone propose a custom framework?
    YesAsk what the standard cannot doNoKeep the standard

4 steps in order. Play them, or step through them one at a time.

5Why Custom Frameworks Are the Worst Option

Every large company has someone who builds an in-house validation library with its own annotations or a fluent rule DSL. It often looks better at first. Ten years later, the author has left, nobody outside knows it, the documentation tools do not understand it, it does not integrate with Spring's error handling, and it has to be migrated at great cost. The standard would have given all that integration for free.

So when someone proposes a custom approach, the question I ask is: what can the standard plus custom constraints not do that we really need? Usually the answer is nothing that a custom ConstraintValidator or a small service method could not cover. If there is a genuine gap, we fill it with an extension of the standard rather than a replacement.

6Follow-up questions

Is Jakarta Validation still evolving, or is it a dead standard?

It is mature rather than dead. Jakarta Validation 3.0 was the namespace change and 3.1, in Jakarta EE 11, brought smaller improvements such as better record support. A slow pace is what we want from a validation standard: it means our annotations keep working.

What about Protobuf or gRPC services?

Protobuf has no built-in validation beyond types, so teams use validation extensions that put rules in the .proto file and generate checks. The same reasoning applies: the schema is the contract, and generated checks keep it in sync. For Java services that also expose REST, the REST DTOs can still use Bean Validation.

How would you migrate a large codebase from hand-written annotations to generation?

Gradually, per API. We first generate the OpenAPI document from the existing code, review and clean it, then switch that API to contract-first generation, with a test that compares old and new validation behaviour on a set of valid and invalid requests. APIs that rarely change can stay code-first.

7Conclusion

In this answer, we weighed the long-term stability and tool support of Jakarta Validation against the drift-free contracts of schema-generated validation, and saw that they combine well as generated DTOs carrying Bean Validation annotations. The choice follows how the company manages API contracts, contract-first or code-first, and the one option to avoid is a custom framework that duplicates the standard.

What to say in the interviewAbout 80 seconds aloud

Open with

I would judge it by what each option gives us over many years and by how the company manages API contracts. Jakarta Validation has been stable since 2009; @NotNull and @Size mean the same today, and everything understands them: Spring MVC, JPA, documentation generators.

Then, if they want more

That stability and tool support are worth a lot. Schema-generated validation, from OpenAPI or JSON Schema, has a different strength: the schema is the single source of truth, so the API contract and the code cannot drift. But these are not really competitors.

Most OpenAPI generators for Java emit DTOs with Jakarta Validation annotations, so at runtime we still use Hibernate Validator and Spring's error handling, while the rules come from the schema. Cross-field rules that schemas cannot express go into custom constraints or the service.

So the decision is about process: if the company designs APIs contract-first, I would generate DTOs with annotations; if it is code-first, hand-written annotations are the source of truth and I would publish the schema from code. In both cases I want contract tests checking schema and behaviour agree.

The thing I would actively avoid is a custom in-house validation framework, because it loses all the ecosystem and becomes a costly migration later.

About this answer

Last updated
12 November 2026
Versions it names
Jakarta EE 11
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "Bean Validation has been part of Java for many years and is now Jakarta Validation. How...": https://scrivio-interview-library.netlify.app/spring-boot/request-validation/b1a4e59328/