Your POJOs :
class MyResponse { private Company company; public MyResponse(Company company) { this.company = company; } // getters & setters } class Company { private String name, age; private List<String> competences; private List<Employee> employees; public Company(String name, String age, List<String> competences, List<Employee> employees) { this.name = name; this.age = age; this.competences = competences; this.employees = employees; } // getters & setters } class Employee { private String name; @SerializedName("phone_number") private String phone; private List<String> skills; public Employee(String name, String phone, List<String> skills) { this.name = name; this.phone = phone; this.skills = skills; } // getters & setters @Override public String toString() { return "Employee{" + "name='" + name + '\'' + ", phone='" + phone + '\'' + ", skills=" + skills + '}'; } }
Deserialization:
String json = "ваша строчка"; Gson gson = new Gson(); MyResponse response = gson.fromJson(json, MyResponse.class); System.out.println(response.getCompany().getEmployees());
The output to the console (for example, the line given in the question):
[Employee {name = 'John', phone = '769453', skills = [Java, Android]}, Employee {name = 'Diego', phone = '987924', skills = [Java, Smart-TV]}, Employee {name = 'Alfred', phone = '452533', skills = [Objective-C, Android, Photoshop]}, Employee {name = 'John', phone = '212456', skills = [Java, Phython]}, Employee {name = 'Mat', phone = '778975', skills = [Android, MovieMaker]}, Employee {name = 'Bob', phone = '456468', skills = [Groovy, Kotlin]}, Employee {name = ' Marty ', phone =' 321789 ', skills = [Android, PHP, C #]}]
Processing Example:
response.getCompany().getEmployees().stream() .filter(employee -> employee.getSkills().contains("Kotlin")) .forEach(System.out::println);
We are looking for all workers who know Kotlin. Output to console:
Employee {name = 'Bob', phone = '456468', skills = [Groovy, Kotlin]}