Dates and numbers can also be customized in the resulting JSON object. @JsonbDateFormat
and @JsonbNumberFormat
are used to configure dates and numbers, respectively. For @JsonbDateFormat
, a DateTimeFormatter
pattern is used to customize the resulting date, and for @JsonNumberFormat
, a DecimalFormat
pattern is used to customize the resulting number. The following example will show how to use both date and number formats:
public class User { private long id; private String name; @JsonbDateFormat("dd/MM/yyy") private Date birthDate; @JsonbDateFormat("dd/MM/yyy hh:mm a") private Date lastLoggedIn; @JsonbNumberFormat("#0.00") private BigDecimal averageLoggedInTime; // getters and setters here } JsonbConfig config = new JsonbConfig().withFormatting(true); Jsonb jsonb = JsonbBuilder.create(config); SimpleDateFormat sdfDate = new SimpleDateFormat("MM/dd/yyyy"); SimpleDateFormat sdfTime = new SimpleDateFormat...