Implementation of a JSON:API server in Java using JAX-RS, Bean Validation, and Java Persistence (JPA). This library is under active development and APIs may not be stable. Please open issues for feature requests or bug reports.
- Simplify configuration, minimize custom interfaces/classes in client application code
- API end point generates JavaScript client module and entities
- Align client interface with JPA
EntityManager
Replace VERSION with the latest from Maven Central:
<dependency>
<groupId>io.xlate</groupId>
<artifactId>jsonapi-rvp</artifactId>
<version>VERSION</version>
</dependency>@Path("/blogapi")
@Transactional // when using JTA transactions
public class BlogResources extends JsonApiResource {
@PostConstruct
void configure() {
Set<JsonApiResourceType<?>> resourceTypes = new HashSet<>();
resourceTypes.add(JsonApiResourceType.define("posts", Post.class)
.build());
resourceTypes.add(JsonApiResourceType.define("comments", Comment.class)
.build());
super.initialize(resourceTypes);
}
}
@Entity
@Table(name = "POSTS")
public class Post {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private long id;
@Column
private String title;
@Column
private String text;
@OneToMany(mappedBy = "post")
private List<Comment> comments;
// ... Getters and Setters
}
@Entity
@Table(name = "COMMENTS")
public class Comment {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private long id;
@Column
private