[
{
"tags": [],
"id": "aaaaaaaaaaaa",
"author": "admin",
"type": "profile",
"description": "",
"name": "defaultProfile1",
"display_name": "Default1"
},
{
"tags": [],
"id": "bbbbbbbbbbbbb",
"author": "admin",
"type": "profile",
"description": "test profile",
"name": "defaultProfile2",
"display_name": "Default2"
}]
this is the response I get from a Get Request, How can I convert this Response to Java List so that I can perform Stream().filter on the list.
To use stream().filter() first you need to convert JSON into POJO and then you can use object mapper provided from Jackson below is the dependency:-
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.9.8</version>
</dependency>
To convert your JSON into POJO you can use below or you can name the class you want:-
public class Author {
public List<String> tags;
public String id;
public String author;
public String type;
public String description;
public String name;
@JsonProperty(value = "display_name")
public String displayName;
// getter - setter
}
Finally, we have to create List of Author so that you can use stream there:-
List<Author> list = Arrays.asList(mapper.readValue(json, Author[].class));
In place of json you can put your response which you are getting from GET api. Now you have created your list of items from JSON. So you can now use streams.