Skip to content

Parse duration config strings like 1s into kotlin.time.Duration #37562

Closed as not planned
@dpozinen

Description

@dpozinen

With an application.yml like so:

my-app:
  duration: 4h

and a class property like so:

import kotlin.time.Duration

@Service
class MyClass(
   @Value("\${my-app.duration}") private val followDuration: Duration
)

getting

Unsatisfied dependency expressed through constructor parameter 3: Failed to convert value of type 'java.lang.String' to required type 'long'; For input string: "PT4h"
...
Caused by: org.springframework.beans.TypeMismatchException: Failed to convert value of type 'java.lang.String' to required type 'long'; For input string: "PT4h"
...
Caused by: java.lang.NumberFormatException: For input string: "PT4h"

Spring boot version: 3.1.4
Kotlin: 1.9.20-Beta

Metadata

Metadata

Assignees

No one assigned

    Labels

    status: declinedA suggestion or change that we don't feel we should currently applytype: enhancementA general enhancement

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions