Vluent 0.0.5 is Released
A couple of weeks ago I wrote about what changed in Vluent in the last few months. All of that is now released as version 0.0.5 and available on Maven Central.
<dependency>
<groupId>io.github.drndivoje</groupId>
<artifactId>vluent</artifactId>
<version>0.0.5</version>
</dependency>
Here is a short summary of everything that went into the release since 0.0.4.
New features
- Spring validator support. The new VluentSpringValidator class wraps any Vluent validator as a Spring validator. You register it in an @InitBinder method and it works with @Valid. Spring is an optional dependency, you only need it if you use this class.
- All errors in the chain. A validation chain does not stop at the first failed rule anymore. ValidationResult keeps a list of all errors, and you get them with getErrors().
- Exceptions are part of the validation. If a value supplier or a validator throws an exception, the chain does not blow up. The exception message is added as a validation error, like any other failed rule.
Bug fixes
- Inverted validation. invert() on a validator did not work correctly. When the original validator passed, the inverted one also passed. Now it fails, as you would expect. Embarrassing, but that is what tests are for. I fixed the wrong tests as well.
Breaking changes
The version starts with 0.0, so I allowed myself to break a few things. These are the changes compared to 0.0.4:
- Packages. The public classes moved from io.github.drndivoje.vluent and io.github.drndivoje.vluent.model to io.github.drndivoje.vluent.api. Everything else is in the internal package and is not exported by the new module-info.java. In most cases updating the imports is enough.
- Error messages. ValidationResult.getErrorMessage() is replaced with getErrors(), which returns a list.
- Converting the result. The ValidationConverter interface is removed. validateAndConvert now takes a plain Java Function, so you can pass a lambda or a method reference:
ResponseEntity<?> response = Vluent.create()
.on(user, new UserValidator())
.validateAndConvert(result ->
result.isSuccess()
? ResponseEntity.ok().build()
: ResponseEntity.badRequest().body(result.getErrors()));
Spring Boot example
I reworked the example project in the repository. It now runs on Spring Boot 4.1.2, has a Maven wrapper, and shows both ways to use Vluent with Spring: with @ValidateBeanWith through Bean Validation, and with VluentSpringValidator. The code is split into dto, service, validation and web packages, so it looks closer to a real application. There is a README with curl commands to try it out.
Housekeeping
I improved the test coverage, fixed the Javadoc warnings, removed the old Travis CI configuration and upgraded central-publishing-maven-plugin to 0.0.9. The README is rewritten as well, and it now starts with the problem Vluent solves before showing any code.
The library still has zero transitive dependencies. The code is on GitHub.