The Crnk JPA module allows to automatically expose JPA entities as JSON:API repositories. No implementation or Crnk-specific annotations are necessary.
The feature set includes:
expose JPA entities to JSON:API repositories
expose JPA relations as JSON:API repositories
decide which entities to expose as endpoints
sorting, filtering, paging, inclusion of related resources.
all default operators of crnk are supported: EQ, NEQ, LIKE, LT, LE, GT, GE.
filter, sort and include parameters can make use of the dot notation to join to related entities. For example, sort=-project.name,project.id, filter[project.name][NEQ]=someValue or include=project.tasks.
support for entity inheritance by allowing sorting, filtering and inclusions to refer to attributes on subtypes.
support for Jackson annotations to customize entity attributes on the JSON:API layer, see here.
DTO mapping support to map entities to DTOs before sending them to clients.
JPA Criteria API and QueryDSL support to issue queries.
filter API to intercept and modify issued queries.
support for computed attributes behaving like regular, persisted attributes.
automatic transaction handling spanning requests and doing a rollback in case of an exception.
OptimisticLockExceptionMapper mapped to JSON:API errors with 409 status code.
PersistenceException and RollbackException are unwrapped to the usually more interesting exceptions like ValidationException and then translated to JSON:API errors.
Not yet supported are sparse field sets queried by tuple queries.
Example
The following gives a brief example of how to setup Crnk with Spring Boot and JPA.
build.gradle
Add Crank dependencies to bundle.gradle.
Remember to make org.springframework.boot and org.springframework.boot:spring-boot-dependencies have the same version.
plugins { id 'org.springframework.boot' version '2.6.2' id 'io.spring.dependency-management' version '1.0.11.RELEASE' id 'java' id 'org.springframework.experimental.aot' version '0.11.1' }
group = 'com.cloudolife.common.configuration.service' version = '0.0.1-SNAPSHOT' sourceCompatibility = '17'