Question

I'm using

andPredicate = Predicates.and(firstPredicate, secondPredicate);

Now I have to serialize the andPredicate (as a JsonObject) and need to access the internal list of the used predicates to gain access to the members of each single predicate.

Is there a way to access these?

Was it helpful?

Solution

If you need behavior like this, the answer is to whip up your own version of Predicates.and(), which isn't too hard at all. Guava's internal implementation for Predicates.and is (correctly) an implementation detail, rather than something exposed to the user.

OTHER TIPS

I think there is no direct way to get this.

Anyway, as a workaround, you could use the toString() method of the andPredicate object. The implementation for this method (listed here ) will return a value like this:

And(<firstPredicate.toString()>, <secondPredicate.toString()>)

Where you can get the parenthesis content, and analyze each entry.

As every entry could also be an and, or, or another compose predicate, be careful on handling the commas and parenthesis.

As the class Javadoc states, andPredicate is already serializable:

All methods returns serializable predicates as long as they're given serializable parameters.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top