2

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 \, ', ".

Alin Valentin
  • 477
  • 6
  • 15
  • Would this help? https://stackoverflow.com/questions/4998748/how-to-prevent-parameter-binding-from-interpreting-commas-in-spring-3-0-5 – riddle_me_this Jan 21 '20 at 14:02

1 Answers1

1

You cannot escape comma for list in spring boot , I'm afraid you will have to think of alternative way to load those environment variables

SandOfTime
  • 692
  • 6
  • 15