funcionality that reads available cities and prints them prepared

This commit is contained in:
Marcin Hutek 2023-12-08 17:38:03 +01:00
parent f5ab4e64be
commit bc5ea0bd76

View File

@ -0,0 +1,31 @@
package model;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.stream.Collectors;
// WYKORZYSTANIE STRUMIENIA
public class CityNames {
public static void cityNamesRead(String filePath) {
ObjectMapper objectMapper = new ObjectMapper();
try {
JsonNode jsonArray = objectMapper.readTree(new File(filePath));
List<String> cityNames = jsonArray
.findValuesAsText("name")
.stream()
.collect(Collectors.toList());
System.out.println("Dostępne miasta:");
cityNames.forEach(System.out::println);
} catch (IOException e) {
e.printStackTrace();
}
}
}