What is the purpose of the @JsonProperty annotation in Jackson?
A) To specify the JSON property name for a field
B) To ignore a field during serialization
C) To define the type of a JSON object
D) To handle exceptions during JSON processing
Answer:
A) To specify the JSON property name for a field
Explanation:
The @JsonProperty
annotation in Jackson is used to specify the name of the JSON property that corresponds to a field in a Java object. This is useful when the JSON property name does not match the field name in the Java class or when you want to customize the property name used in the JSON output.
For example:
public class SomeClass {
@JsonProperty("full_name")
private String name;
// other fields
}
In this example, the name
field will be serialized and deserialized with the JSON property name “full_name” instead of “name”.