Bird
0
0

Consider this DTO:

medium📝 component behavior Q5 of 15
Spring Boot - Request and Response Handling
Consider this DTO:
public class ProductDto {
  @NotNull
  private String name;
  @Min(1)
  private int quantity;
}
What happens if a client sends JSON with quantity as 0?
AValidation passes and the product is accepted.
BValidation fails because quantity must be at least 1.
CValidation fails because quantity cannot be zero or negative but 0 is allowed.
DValidation ignores the quantity field.
Step-by-Step Solution
Solution:
  1. Step 1: Analyze @Min(1) constraint on quantity

    The @Min(1) annotation requires the quantity to be 1 or greater.
  2. Step 2: Check input value against constraint

    A value of 0 is less than 1, so validation fails.
  3. Final Answer:

    Validation fails because quantity must be at least 1. -> Option B
  4. Quick Check:

    @Min(1) rejects 0 = A [OK]
Quick Trick: @Min(1) means value must be 1 or more [OK]
Common Mistakes:
  • Thinking 0 passes @Min(1)
  • Confusing @Min with @NotNull
  • Assuming validation ignores numeric fields

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Spring Boot Quizzes