Easing data and objects representation with JSON-B
This recipe will show you how you can use the power of the new JSON-B API to give some flexibility to your data representation, and also help to transform your objects into JSON messages.
Getting ready
Start by adding the Java EE dependency:
<dependencies>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>8.0</version>
<scope>provided</scope>
</dependency>
</dependencies>
How to do it...
- 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, ...