0

So I have an object Structure like the following:

I have a Person Object which has a list of Friends (named friends in Person) - That list of Friends has a Map (named information) - The map has a Key of 'age' and a value of an string

So I am looking to return one Friend where the age of that friend is equal to lets say 20

public class Person {
    private List<Friend> friends;

    public List<Friend> getFriends() {
        return friends;
    }

    public void setFriends(List<Friend> friends) {
        this.friends = friends;
    }
}


public class Friend {
    private Map<String, Object> information;

    public Map<String, Object> getInformation() {
        return information;
    }

    public void setInformation(Map<String, Object> information) {
        this.information = information;
    }
}

Here is what I was thinking but couldn't get it to work please let me know if I am missing something

Friend match = (Friend)JXPathContext.newContext(personInput).getValue("friends/information[@name='age' = '20']//friend"); 
mstelz
  • 610
  • 4
  • 9
  • 19

1 Answers1

0

You need to select all the objects under the "friends" link that have an information map that contains an "age" equals to 20. Then you only want the first result.

Friend match = (Friend)JXPathContext.newContext(personInput).getValue("friends[information/age = '20'][1]");
JP Moresmau
  • 7,388
  • 17
  • 31