Skip to content

Add input validation to Employee REST API#42

Open
devin-ai-integration[bot] wants to merge 1 commit intomasterfrom
devin/1777591604-add-input-validation
Open

Add input validation to Employee REST API#42
devin-ai-integration[bot] wants to merge 1 commit intomasterfrom
devin/1777591604-add-input-validation

Conversation

@devin-ai-integration
Copy link
Copy Markdown

@devin-ai-integration devin-ai-integration Bot commented Apr 30, 2026

Summary

Adds Bean Validation constraints to the Employee REST API so that invalid input is rejected with a 422 response before reaching the database.

Changes:

  • Employee entity: Added @NotBlank and @Size(min=1, max=255) annotations to firstName, lastName, and jobTitle fields. This rejects null, empty, and whitespace-only values, and enforces a 255-character max length.
  • EmployeeResource: Added @Valid on the createEmployee method parameter so Dropwizard triggers validation automatically and returns structured error responses on constraint violations.
  • pom.xml: Added jaxb-api and jaxb-runtime as test-scoped dependencies for Java 11 compatibility.
  • EmployeeValidationTest: 11 new test cases covering valid input, null/empty/blank values for each field, all-null input, max-length boundary, and over-max-length rejection.

Review & Testing Checklist for Human

  • Verify 422 responses are returned when POSTing invalid Employee JSON (null, empty, or blank fields; fields exceeding 255 chars)
  • Confirm valid Employee creation still works as expected via POST /employee
  • Review that @NotBlank from org.hibernate.validator.constraints is appropriate for the Dropwizard 1.0.5 / Hibernate Validator 5.x version in use

Notes

  • Dropwizard's built-in ConstraintViolationExceptionMapper handles the error response formatting automatically — no custom exception mapper was needed.
  • The @NotBlank annotation covers both null and whitespace-only checks, while @Size adds the upper bound constraint.

Link to Devin session: https://app.devin.ai/sessions/29e94bdec4d9451283bc8fb83f12be2e
Requested by: @WesternConcrete


Devin Review

Status Commit
⚪ Not started

Run Devin Review

💡 Connect your GitHub account to enable automatic code reviews.

Open in Devin Review (Staging)

- Add @notblank and @SiZe annotations to Employee entity fields
  (firstName, lastName, jobTitle)
- Add @Valid annotation to createEmployee endpoint parameter
- Add JAXB test dependencies for Java 11 compatibility
- Add EmployeeValidationTest with 11 test cases covering null, empty,
  blank, max-length, and over-max-length inputs

Co-Authored-By: Wes Convery <2wconvery@gmail.com>
@devin-ai-integration
Copy link
Copy Markdown
Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

Copy link
Copy Markdown
Author

@devin-ai-integration devin-ai-integration Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no potential bugs to report.

View in Devin Review to see 1 additional finding.

Open in Devin Review

@devin-ai-integration
Copy link
Copy Markdown
Author

End-to-End Test Results

Tested input validation on POST /employee by running the server locally and issuing curl requests against it. All 6 tests passed.

Validation Tests (6/6 passed)
# Test Expected Actual Result
1 Valid employee creation HTTP 200 + employee JSON 200{"id":2,"firstName":"Alice","lastName":"Smith","jobTitle":"Senior Dev"} PASSED
2 Missing firstName HTTP 422 + error referencing firstName 422{"errors":["firstName may not be empty"]} PASSED
3 Whitespace-only jobTitle (" ") HTTP 422 (proves @NotBlank not just @NotNull) 422{"errors":["jobTitle may not be empty"]} PASSED
4 256-char firstName HTTP 422 (proves @Size(max=255)) 422{"errors":["firstName size must be between 1 and 255"]} PASSED
5 Empty {} body HTTP 422 with 3 errors (one per field) 422 — 3 errors for firstName, lastName, jobTitle PASSED
6 Invalid data NOT persisted GET /employee returns only valid records Only 2 valid records returned, no invalid data PASSED

No escalations. Devin session

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant