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 java.util.concurrent.CompletableFuture; import com.google.gson.Gson; import com.google.gson.GsonBuilder; public class App { public static void main(String[] args) throws Exception { String text = getEmployees().join(); printNames(text); } public static CompletableFuture getEmployees() throws IOException, InterruptedException { HttpClient client = HttpClient.newHttpClient(); HttpRequest request = HttpRequest.newBuilder() .uri( URI.create("http://[::1]:3000/employees")) .build(); return client.sendAsync(request, BodyHandlers.ofString()) .thenApply(HttpResponse::body); } public static void printNames(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); } } }