import java.net.HttpURLConnection; import java.net.URL; import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.Arrays; import com.google.gson.Gson; import com.google.gson.GsonBuilder; public class App { public static void main(String[] args) throws Exception { System.out.println("REST API lekérés"); URL url = new URL("http://localhost:3000/employees"); HttpURLConnection http = (HttpURLConnection) url.openConnection(); http.setRequestMethod("GET"); http.connect(); String text = null; int responseCode = http.getResponseCode(); if (responseCode != 200) { throw new RuntimeException("Http válasz: " + responseCode); }else { text = new String( http.getInputStream().readAllBytes(), StandardCharsets.UTF_8); } GsonBuilder builder = new GsonBuilder(); builder.setPrettyPrinting(); Gson gson = builder.create(); Employee[] employeeArray = gson.fromJson(text, Employee[].class); ArrayList list = new ArrayList<>(Arrays.asList(employeeArray)); for(Employee employee: list) { System.out.println(employee.name); } } }