You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Add conversion support for java.time.Duration [SPR-13579] #18156
Java 8's java.time.Duration is a good choice for defining durations of time, and arguably better than using a long with a property name to specify the units.
It would be good to support conversion from a String to make it easier to use beans that use this in their API.
I, too, started to use Duration for configuration properties rather than things like "someTimoutMillis". I realized Spring does not offer out-of-the-box conversion from String to Duration, at least not when using context:property-override, so a created a PR #1231 -- all this before finding this issue.
This issue is closed, but I tested Spring master branch and couldn't get expected behavior (no conversion was found) before applying my patch. I see Joseph Walton adds completely different class than my PR, so I guess this isn't equivalent, Maybe I understand "conversion" differently than this issue. Juergen Hoeller could you please have a look?
Piotr Findeisen, we're only supporting Duration and Period in org.springframework.format's JSR-310 package at this point, along with the general date-time types, analogous to Joda-Time. The ISO text representations for date-time types are arguably rather serialization-oriented and not really intuitive for user-driven configuration purposes, which is why we haven't added them to the core property editors.
If you'd like to enable such ISO formatting rules for configuration purposes, set up your application context with a DefaultFormattingConversionService out of the box, e.g. a bean with name "conversionService" which will get picked up for bean property values as well then.
Juergen Hoeller, thanks for your response. I didn't know about formatters and that they can be plugged as property editors. Thanks for explaining this to me.
The ISO text representations for date-time types are arguably rather serialization-oriented and not really intuitive for user-driven configuration purposes
I couldn't disagree. So what do you think about arguably more intuitive format (e.g. "12 s") provided as property editor, with the intention to cover said configuration purposes? Would such a think find its place in Spring?
Activity
spring-projects-issues commentedon Oct 16, 2015
Joseph Walton commented
This is similar to #11372, but only for
java.time, rather than JODA.spring-projects-issues commentedon Oct 17, 2015
Joseph Walton commented
PR: SPR-13579: Support conversion from Strings to Java 8 Durations..
spring-projects-issues commentedon Nov 9, 2016
Piotr Findeisen commented
Hi,
I, too, started to use
Durationfor configuration properties rather than things like "someTimoutMillis". I realized Spring does not offer out-of-the-box conversion from String to Duration, at least not when usingcontext:property-override, so a created a PR #1231 -- all this before finding this issue.This issue is closed, but I tested Spring master branch and couldn't get expected behavior (no conversion was found) before applying my patch. I see Joseph Walton adds completely different class than my PR, so I guess this isn't equivalent, Maybe I understand "conversion" differently than this issue. Juergen Hoeller could you please have a look?
spring-projects-issues commentedon Nov 25, 2016
Juergen Hoeller commented
Piotr Findeisen, we're only supporting
DurationandPeriodinorg.springframework.format's JSR-310 package at this point, along with the general date-time types, analogous to Joda-Time. The ISO text representations for date-time types are arguably rather serialization-oriented and not really intuitive for user-driven configuration purposes, which is why we haven't added them to the core property editors.If you'd like to enable such ISO formatting rules for configuration purposes, set up your application context with a
DefaultFormattingConversionServiceout of the box, e.g. a bean with name "conversionService" which will get picked up for bean property values as well then.spring-projects-issues commentedon Nov 25, 2016
Piotr Findeisen commented
Juergen Hoeller, thanks for your response. I didn't know about formatters and that they can be plugged as property editors. Thanks for explaining this to me.
I couldn't disagree. So what do you think about arguably more intuitive format (e.g. "12 s") provided as property editor, with the intention to cover said configuration purposes? Would such a think find its place in Spring?