Spring boot: Read json file and convert it to pojo

preview_player
Показать описание
Check it out! better/simpler/easier way.
---------------------------------------------------------------------------------------------------------------
1. create a method that reads json file and covert json to java object.
2. let's refactor the method. make it generic!

#spring boot #jsonToPojo #objectMapper #generic
Рекомендации по теме
Комментарии
Автор

List<Item> items = getListFromJson(path) - there will be convertation error. This code not working properly

threadoff
Автор


You can do
List<Item> items = getListFromJson(path);

But you can't do
Item item = items.get(0); and
Item item = getListFromJson(path).get(0);
It will throw class cast exception.

There is actually easier way of doing it, but it is pretty similar to what I did in this video. So I just decided not to upload before. But I will upload it soon

cellonlush