I have a bunch of Spring configuration files in various formats from various projects. I am doing some analytics on the combined merged results of the properties files.
So I would like to parse out the hierarchy of each file (yaml, json and properties files).
But the trick is I need to convert each property key into canonical form before I store it into the data structure. because of this stuff https://github.com/spring-projects/spring-boot/wiki/Canonical-properties
Namely:
spring.jpa.database-platform=mysql
spring.jpa.databasePlatform=mysql
spring.JPA.database_platform=mysql
Each of these properties is the exact same.
So the tricky part here is that each property key needs to be converted to canonical form before doing any sort of comparison.
Is there a Spring-friendly-way to convert keys to and from the canonical form?
Examples:
databasePlatform
-> database-platform
dataBasePlatform
-> data-base-platform
Because I have found random canonical string snippets on the internet and none of them seem to work quite like Spring's does.
Any advise how to proceed here is welcome thanks.
Here is what I've found so far:
public String convertToCanonicalForm(String key) {
return key.replaceAll("(.)(\\p{Upper}+|\\d+)", "$1-$2").toLowerCase();
}
but I'm not sure about some of the edge cases. How do you handle abc123
is it abc-123
or abc123
? Or what about a123
is that a-123
or just a123
? Or what about A123
is that a-123
or a123
? etc.
UPDATE: I found a better function here, but not sure if this is adequate: https://stackoverflow.com/a/70226943/1174024
public String convertToCanonicalForm(String key) {
return key.replaceAll("([a-z])([A-Z])", "$1-$2").toLowerCase();
}