REST resources can have multiple representations (e.g., JSON, XML) as different clients may request different formats. The mechanism for selecting the appropriate representation is called content negotiation. By default, it uses application/json unless modified.

Content negotiation enables a single endpoint to support various resource representation types based on client requests.

Content Negotiation Strategies

Content negotiation can be implemented in the following ways, listed by precedence:

  1. Using Path Extension
  2. Using URL Parameter
  3. Using Accept Headers

Serialization and Deserialization in Spring Boot

Spring Boot uses Jackson as the default vendor for marshalling (serialization: Java → JSON) and unmarshalling (deserialization: JSON → Java).

Customizing Property Names

To customize the names of properties during serialization and deserialization, use the Jackson annotation @JsonProperty.

Example:

@JsonProperty(value="mesg")
private String message;

This maps the Java field message to the JSON property mesg.

Controlling Property/Field Access

You can control property access during serialization and deserialization using the access attribute of @JsonProperty: