import java.io.IOException; import java.net.URI; import java.net.http.HttpClient; import java.net.http.HttpRequest; import java.net.http.HttpResponse; import java.net.http.HttpResponse.BodyHandlers; 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 { String text = getEmployees(); printName(text); } public static String getEmployees() throws IOException, InterruptedException { HttpClient client = HttpClient.newHttpClient(); HttpRequest request = HttpRequest.newBuilder() .uri( URI.create("http://[::1]:3000/employees")) .build(); HttpResponse response = client.send(request, BodyHandlers.ofString()); String text = response.body(); return text; } public static void printName(String text) { 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); } } }