How to do it...

  1. We first create a User class with some customization (details ahead):
public class User {    private Long id;        @JsonbProperty("fullName")    private String name;        private String email;        @JsonbTransient    private Double privateNumber;        @JsonbDateFormat(JsonbDateFormat.DEFAULT_LOCALE)    private Date dateCreated;        public User(Long id, String name, String email,                 Double privateNumber, Date dateCreated) {        this.id = id;        this.name = name;        this.email = email;        this.privateNumber = privateNumber;        this.dateCreated = dateCreated;    }    private User(){    }    //DO NOT FORGET TO IMPLEMENT THE GETTERS AND SETTERS}
  1. Here we use UserView to return the user JSON to the UI:
@ViewScoped@Namedpublic class UserView implements Serializable{     private String json; ...

Get Java EE 8 Cookbook 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.