I need to have configurable timeout for a project, which reads different configs from YAML file.
I noticed that java.time.Duration
has method parse which is used by Jackson to deserialize duration strings. The problem is that it uses ISO-8601 formatting and expects the duration to have PnDTnHnMn.nS
format. While it is a good idea to follow standards, asking people provide timeout as PT10M
is not the best option and 10m
is preferred.
I did write a custom deserializer for duration fields, but seems strange that Jackson can't handle this by default.
What is the easiest way to deserialize human friendly 10m
, 5s
and 1h
to java.time.Duration
using Jackson ObjectMapper?