How to do it...

You need to perform the following steps to complete this recipe:

  1. We are going to build a JAX-RS-based application, so we will start by preparing the application:
@ApplicationPath("webresources")public class Application extends javax.ws.rs.core.Application {}
  1. Then, we will create a User class as our main object:
public class User implements Serializable {    private String name;    private String email;    //DO NOT FORGET TO ADD THE GETTERS AND SETTERS}
  1. Our User class doesn't have a default constructor, so Jakarta CDI doesn't know how to construct the class when it tries to inject it. Therefore, we need to create a factory class and use the @Produces annotation over its methods:
public class UserFactory implements Serializable{ ...

Get Jakarta EE Cookbook - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.