This question is a duplicate of the following question, which is over 5 years old and hasn't received an accepted answer.
How to escape "," (comma) in Spring String to array or List conversion
I have a docker-contained spring-application which is customisable via environment variables.
Spring will pick up the environment variables and map them to the fields in configuration classes.
One such field is a List<String>
. It correctly splits my environment variable on the comma character. The issue comes when one of my fields contains a comma.
I tried the following:
-e LIST1='"1","2a,2b","3"'
-e LIST2="'1','2a,2b','3'"
-e LIST3="1,2a\,2b,3"
-e LIST4="1,2a\\,2b,3"
-e LIST5='1,2a\,2b,3'
-e LIST6='1,2a\\,2b,3'
In every scenario, spring simply does a string split over the comma character, resulting in some of my values containing characters such as \
, '
, "
.