Simple project that demonstrates Spring Boot JSON serialization/deserialization and validation using a simple entity model of Product
and ProductType
objects.
Features:
- Spring Boot
- Simple JSON rest endpoints
- Custom JSON serialization/deserialization
- Caching
- JPA + Spring Data Repositories
- Flyway database migration
- Mock MVC testing using jsonPath()
- Jacoco code coverage (with custom exclusions)
Example method with request validation.
@PostMapping("/product")
public ResponseEntity<Product> addProduct(@Valid @RequestBody Product product) {
return ResponseEntity.ok(service.save(product));
}
The code can be tested using:
$ ./gradlew clean check
To start the application:
$ ./gradlew bootRun
The application is available on http://localhost:8080 (You can view the application health on http://localhost:8080/actuator/health)
POST http://localhost:8080/product
{
"name": "Product1",
"type": "X1",
"category": "insurance",
"subCategory": "life insurance",
"roleStart": "2021-01-03T11:00:01",
"roleEnd": null
}
POST http://localhost:8080/product
{
"name": null,
"type": "foo",
"category": null,
"subCategory": null,
"roleStart": null,
"roleEnd": null
}
GET http://localhost:8080/product/{id}
GET http://localhost:8080/productTypes
PATCH http://localhost:8080/product/{id}
{
"name": "Product2",
"type": "R3",
"category": "insurance",
"subCategory": "life insurance",
"roleStart": "2021-02-03T11:00:01",
"roleEnd": null
}
POST http://localhost:8080/cache
RESET