Search code examples
yaml

Preserve leading space in application yaml properties


I've got a list of properties in yml file

foo:
    bar:  One., Two., Three

when converting them to list

@Value("\${foo.bar}")
public var listOfBar: List<String> = mutableListOf()

Leading spaces are trimmed so I get "One." "Two." "Three.", but what I need is " One." " Two." " Three." with spaces before each. Putting '\u0020' in front didn't helped, it got trimmed anyway.


Solution

  • I ended up doing this. And it's worked

     @Value("#{'\${foo.bar}'.split(',')}")
     public var listOfBar: List<String> = mutableListOf()
    

    and surrounded properties with "

    foo:
        bar:  " One., Two., Three"