Spring-boot: SpringBoot2 ConfigurationProperties removes colon from yaml keys

Created on 20 Dec 2017  Â·  9Comments  Â·  Source: spring-projects/spring-boot

Until SpringBoot 1.5.9
I was using the application yaml to define a namespaced id with few properties.
eg.

app:
    ids:
      "urn:test:id:12-34" :
        roles:
          - CREATE
          - ALLOW_ALL
      "urn:test:id:23-41" :
        roles:
          - DELETE
          - ALLOW_ALL

This was being read in as a Map

@ConfigurationProperties(prefix = "app")
@Data
@Component
public class IdProps {
  @Data
  public static class IdProps {
    private Map<String, Id> ids = new HashMap<>();
  }

  @Data
  public static class Id {
    private List<String> roles = new ArrayList<>();;
  }
}

The expectation was that this worked in SpringBoot2.

However, the Map keys in SPringBoot2 were as below
"urntestid12-34" -> "IdProps.Id(roles=[CREATE, ALLOW_ALL])"

Expected behavior
"urn:test:id:12-34" -> "IdProps.Id(roles=[CREATE, ALLOW_ALL])"

invalid

Most helpful comment

@balajeetm the new properties binder strips off all characters that are not alphanumeric or - so that properties can be read in a uniform manner. For map keys that have special characters in them, you can surround the key name with [] so that the key gets used as specified, for example, '[urn:test:id:12-34]'.

All 9 comments

@balajeetm the new properties binder strips off all characters that are not alphanumeric or - so that properties can be read in a uniform manner. For map keys that have special characters in them, you can surround the key name with [] so that the key gets used as specified, for example, '[urn:test:id:12-34]'.

I should have closed this myself. Thanks. It works. @mbhave / @snicoll , Any tentative timelines on Spring Boot 2 GA? I'm waiting to move to prod

@balajeetm The current release plan dates are here.

Thanks @philwebb

Uuh it took me two hours to handle this in my properties until I found this issue here. Is there already a tiny part in the migration wiki which documents this change in the behaviour of the properties binder respective the use of the protecting brackets []?

@mle-enso the Migration guide links to this which specifies how to deal with map keys that have non-alphanumeric characters in them.

Ah thanks for the hint. Actually our property binding looks like the following with not really dots in the keys:

[…]
@ConfigurationProperties(prefix = "property-prefix")
public class ConfigurationClass {
    Map<Long, Map<Long, Integer>> propertyKey;
    […]
}

and the corresponding properties:

property-prefix.propertyKey.[11].[30311]=10
property-prefix.propertyKey.[11].[3626]=19
[…]
property-prefix.propertyKey.[4].[30311]=20
property-prefix.propertyKey.[4].[3626]=29

Until 2.0.0.M7 all that worked without the brackets in the properties, now they are necessary although I am not really happy with this, cause I do not really need to protect dots in my keys.

So may be one last question… is this the way to go for us or do you recommend another approach/fix for our binding?

@mle-enso Your issue seems related to this. If not and if you want to report a bug or request an enhancement, please open a new issue. If you have other questions, Stack Overflow is more suited for that.

Thanks for your quick feedback... I'll take a deeper look in your referenced issue and then proceed accordingly.

Was this page helpful?
0 / 5 - 0 ratings