import java.io.BufferedReader; import java.io.FileNotFoundException; import java.io.FileReader; import java.lang.reflect.Type; import java.time.LocalDate; import java.time.format.DateTimeFormatter; import java.util.ArrayList; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.google.gson.JsonDeserializationContext; import com.google.gson.JsonDeserializer; import com.google.gson.JsonElement; import com.google.gson.JsonParseException; public class Mainconsole { ArrayList placeList; public Mainconsole() { this.placeList = new ArrayList<>(); this.readFile(); } public void readFile() { try { tryReadFile(); } catch (FileNotFoundException e) { System.err.println("Hiba! A fájl nem található!"); } } public void tryReadFile() throws FileNotFoundException { Gson gson = new GsonBuilder().registerTypeAdapter(LocalDate.class, new JsonDeserializer() { @Override public LocalDate deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { return LocalDate.parse(json.getAsString(), DateTimeFormatter.ofPattern("yyyy-MM-dd")); } }).create(); FileReader fr = new FileReader("database.json"); BufferedReader br = new BufferedReader(fr); Place[] data = gson.fromJson(br, Place[].class); for(Place place : data) { placeList.add(place); System.out.println(place.name); } } }