Challenge - 5 Problems
Spring Boot Validation Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate2:00remaining
What happens when a value violates @Min constraint?
Consider a Spring Boot REST controller receiving a JSON with a field annotated with @Min(5). What happens if the client sends a value of 3 for that field?
Spring Boot
@RestController public class SampleController { @PostMapping("/test") public String test(@Valid @RequestBody InputData data) { return "Value accepted"; } } public class InputData { @Min(5) private int number; // getters and setters }
Attempts:
2 left
💡 Hint
Think about how Spring Boot handles validation annotations with @Valid.
✗ Incorrect
When a field annotated with @Min receives a value below the minimum, Spring Boot's validation framework rejects the request and returns a 400 error with details about the violation.
📝 Syntax
intermediate1:30remaining
Which code snippet correctly applies @Max to a field?
Select the code snippet that correctly uses @Max to restrict a numeric field to a maximum value of 100.
Attempts:
2 left
💡 Hint
Check the official annotation parameter name for @Max.
✗ Incorrect
The @Max annotation takes a single value parameter without a name, so @Max(100) is correct. Using named parameters like value=100 also works but is less common. max= or limit= are invalid.
❓ state_output
advanced2:00remaining
What is the validation result for a field annotated with both @Min and @Max?
Given a field annotated with @Min(10) and @Max(20), what happens if the input value is 25?
Spring Boot
public class Data { @Min(10) @Max(20) private int value; // getters and setters }
Attempts:
2 left
💡 Hint
Consider which constraint is violated by the input value.
✗ Incorrect
The input value 25 is above the maximum 20, so validation fails with a message about exceeding the maximum. The minimum constraint is satisfied, so no message about it appears.
🔧 Debug
advanced2:30remaining
Why does this @Min annotation not work as expected?
Identify the issue in this code snippet where @Min(1) is applied but negative values are still accepted.
Spring Boot
public class Product { @Min(1) private Integer quantity; // getters and setters }
Attempts:
2 left
💡 Hint
Think about how validation is triggered in Spring Boot controllers or services.
✗ Incorrect
Validation annotations like @Min only trigger when the object is validated, typically with @Valid. Without @Valid on the object, constraints are ignored.
🧠 Conceptual
expert3:00remaining
How does Spring Boot handle @Min and @Max on floating-point numbers?
If a field is a double and annotated with @Min(1) and @Max(10), which statement is true about validation behavior?
Spring Boot
public class Measurement { @Min(1) @Max(10) private double value; // getters and setters }
Attempts:
2 left
💡 Hint
Consider how Bean Validation API defines @Min and @Max behavior for floating types.
✗ Incorrect
The Bean Validation specification treats @Min and @Max as applying to the long value of the number, so the fractional part is truncated before comparison.