Skip to content

Add conversion support for java.time.Duration [SPR-13579] #18156

Closed

Description

@spring-projects-issues

Joseph Walton opened SPR-13579 and commented

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.


Issue Links:

Activity

  1. spring-projects-issues commented on Oct 16, 2015

    @spring-projects-issues
    CollaboratorAuthor

    Joseph Walton commented

    This is similar to #11372, but only for java.time, rather than JODA.

  2. spring-projects-issues commented on Oct 17, 2015

    @spring-projects-issues
    CollaboratorAuthor
  3. spring-projects-issues commented on Nov 9, 2016

    @spring-projects-issues
    CollaboratorAuthor

    Piotr Findeisen commented

    Hi,

    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?

  4. spring-projects-issues commented on Nov 25, 2016

    @spring-projects-issues
    CollaboratorAuthor

    Juergen Hoeller commented

    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.

  5. spring-projects-issues commented on Nov 25, 2016

    @spring-projects-issues
    CollaboratorAuthor

    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.

    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?

  6. added
    type: enhancement
    in: core
    status: duplicate
    on Jan 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

in: corestatus: duplicatetype: enhancement

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions