Ask Your Question
0

What is the method to transmit a map<String,Map<String,Integer>> along with application.properties?

asked 2022-05-27 11:00:00 +0000

devzero gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2022-07-22 09:00:00 +0000

nofretete gravatar image

One way to transmit a map<string,map<string,integer>> along with application.properties is to convert the map into a JSON object and include it as a string value in the properties file.

For example, if the map is called "data", we can use the following code to convert it into a JSON string:

ObjectMapper objectMapper = new ObjectMapper();
String jsonData = objectMapper.writeValueAsString(data);

We can then include this JSON string as a value in the application.properties file using a key of our choice, like so:

my.map.data={JSON string here}

In the application code, we can then retrieve this JSON string, parse it back into the original map type, and use it in our application.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2022-05-27 11:00:00 +0000

Seen: 14 times

Last updated: Jul 22 '22