0

I have a json file with array of objects, i want to read it and create rest api with couple GET methods. What are best practices to do so? Should i create in memory database (H2), save json objects there and then do the rest? I am looking for most efficient solution.

2 Answers 2

1

If the data is static and you’re just doing GET requests, in your data layer you can just read from the contents of the file into POJOs. Then if you need to get more sophisticated you can always change up the implementation detail to H2 or some other DB.

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

Comments

1

If you JSON file is small and does not change frequently, you do not need to put it in H2 or another database. Just read the JSON file from the disk once and use it in your REST API endpoints.

Jackson is a good library for processing JSON data in Spring Boot. It offers multiple options to read and consume the JSON data.

2 Comments

Thank you for answer, ill follow your advice. I saw someone using H2 database for same thing but with xlsx file. Do you mind explaining when it is a good idea to use database?

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.