0
ServiceApplicationTest{
  public static final String CONNECTED_CALL="{\"Sid\":\"835494\",\"Info\":\"121345\"}
}

Strings like "CONNECTED_CALL" can be very long, this is not preety but is working fine. My goal is to move all this kind of data to file in resource folder like - connectedCall.json and read it without making any major change.

I dont want to change already written code, I am fine with adding complexity to populate this values.

One way I had is to read these json file as string, calling this function for every value but then they cant be final.

Can i do it using any annotation? like @Value in spring boot. I am using jackson.

2
  • Reading json file but they can't be final? What do you mean by that? Commented Jul 23, 2022 at 8:18
  • @Enfieldli- final strings have to declared and initialised together. Commented Jul 24, 2022 at 15:16

1 Answer 1

2

I think you can use @PropertySource something like :

@Configuration
@PropertySource("classpath:json.properties")
public class JsonConfig {
       
       @Value("${CONNECTED_CALL}")
       String jsonVal;
}

And your json.properties file will have :

CONNECTED_CALL="{\"Sid\":\"835494\",\"Info\":\"121345\"}

This can be one of the way.

Sign up to request clarification or add additional context in comments.

2 Comments

This will pollute my properties file. Only properties file related on the basis of deployment are allowed.
Then another option which I can think of is to use db or file storage & refer it in your application either via repository interface or via any db drivers.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.