Gino Corpuz
Gino Corpuz

Reputation: 130

Jackson deserialize array of json objects ignoring some of the objects

Suppose I have this JSON Array

[{"type":"type1", "id":"1", "name":"John"},
 {"type":"type1", "id":"2", "name":"Jane", 
 {"type":"type2", "id":"3", "name":"Joseph"}]

And I have these Java objects

public class Person {
    Long id;
    String name;
    String type;
}

public class MainClass {
    List<Person> persons;
}

Is there a way to deserialize the JSON array such that only those that are type type1 will be included? Those with type2 should not be set as null but completely ignored.

Upvotes: 0

Views: 551

Answers (1)

Sharon Ben Asher
Sharon Ben Asher

Reputation: 14328

I think you can achieve that with Jackson Filter

Upvotes: 1

Related Questions