You should implement a customer deserializer. See the Awita's answer.
However, just for the record, there is an official datatype Jackson module which recognizes Java 8 Date & Time API data types. It represents Period
as a string in the ISO-8601 format, not as object your stated. But if you are willing to change the format, you can consider using that module.
Here is an example:
public class JacksonPeriod {
public static void main(String[] args) throws JsonProcessingException {
final ObjectMapper objectMapper = new ObjectMapper();
objectMapper.registerModule(new JavaTimeModule());
final Period period = Period.of(1, 2, 3);
final String json = objectMapper.writeValueAsString(period);
System.out.println(json);
}
}
Output:
"P1Y2M3D"