This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| "errors": [ | |
| { | |
| "code": "firstName", | |
| "message": "First name must be between 2 and 25 characters" | |
| }, | |
| { | |
| "code": "title", | |
| "message": "Title cannot be null" | |
| }, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class FormattedNameResponseMapper { | |
| private FormattedNameResponseMapper() { | |
| } | |
| public static FormattedNameResponse fromWebExchangeBindException(WebExchangeBindException ex) { | |
| FormattedNameResponse res = new FormattedNameResponse(); | |
| List<Error> errors = ex.getFieldErrors().stream() | |
| .map(fieldError -> new Error(fieldError.getField(), fieldError.getDefaultMessage())) | |
| .collect(Collectors.toList()); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @RestController | |
| public class ValidationDemoController { | |
| @PostMapping("/format") | |
| public Mono<ResponseEntity<FormattedNameResponse>> format(@Valid @RequestBody Mono<FormatNameRequest> request) { | |
| return request | |
| .map(res -> ResponseEntity.status(HttpStatus.OK).body(FormattedNameResponseMapper.fromFormatNameRequest(res))) | |
| .onErrorResume(WebExchangeBindException.class, | |
| ex -> Mono.just(ResponseEntity.status(HttpStatus.BAD_REQUEST) | |
| .body(FormattedNameResponseMapper.fromWebExchangeBindException(ex)))); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package org.kds.reactive.model; | |
| import javax.validation.constraints.NotBlank; | |
| import javax.validation.constraints.NotNull; | |
| import javax.validation.constraints.Size; | |
| public class FormatNameRequest { | |
| @NotNull(message = "Title cannot be null") | |
| private String title; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| plugins { | |
| id 'org.springframework.boot' version '2.3.0.RELEASE' | |
| id 'java' | |
| id 'idea' | |
| } | |
| apply plugin: 'io.spring.dependency-management' | |
| group = 'org.kds.reactive' | |
| version = '0.0.1-SNAPSHOT' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Request | |
| POST http://host:port/format | |
| Content-Type: application/json | |
| { | |
| "title":"Mr", | |
| "firstName":"Jhon", | |
| "middleName": "Martin", | |
| "lastName": "Smith" | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| private static void debuggingUsingHook() { | |
| Hooks.onOperatorDebug(); | |
| List<String> nameList = Arrays.asList("Rochel", "April", "Hong"); | |
| Flux<String> stringFlux = Flux.fromIterable(nameList) | |
| .distinct() | |
| .map(name -> name.substring(0, 3)) | |
| .map(String::toUpperCase) | |
| .map(name -> { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| private static void debuggingUsingCheckpoints() { | |
| List<String> nameList = Arrays.asList("Rochel", "April", "Hong"); | |
| Flux<String> stringFlux = Flux.fromIterable(nameList) | |
| .distinct() | |
| .checkpoint("after distinct()") | |
| .map(name -> name.substring(0, 3)) | |
| .checkpoint("after substring") | |
| .map(String::toUpperCase) | |
| .checkpoint("after toUpperCase") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| private static void debuggingWithOutCheckpoints() { | |
| List<String> nameList = Arrays.asList("Rochel", "April", "Hong"); | |
| Flux<String> stringFlux = Flux.fromIterable(nameList) | |
| .distinct() | |
| .map(name -> name.substring(0, 3)) | |
| .map(String::toUpperCase) | |
| .map(name -> { | |
| if (name.equals("HON")) { | |
| throw new RuntimeException("Boom!"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| private static void debuggingUsingLogOperator() { | |
| List<String> nameList = Arrays.asList("Rochel", "April", "Hong"); | |
| Flux<String> stringFlux = Flux.fromIterable(nameList) | |
| .distinct() | |
| .map(name -> name.substring(0, 3)) | |
| .map(String::toUpperCase) | |
| .log(); | |
| stringFlux.subscribe(log::info); |
NewerOlder