I have a class like this:
class Foo { String bar }
I am trying to get the identifiers of all Foo
objects whose string bar
String is in the list of bars
. I tried several ways, always getting the same error:
java.lang.String cannot be cast to java.util.Collection
Some of the things I tried:
def ids = Foo.findAllByBarInList( bars )*.id def ids = Foo.findAllByBarInList( bars ).collect{ it.id } def ids = Foo.findAllByBarInList( bars ).collect{ it -> it?.id }
UPDATE:
I did bars
with split , so it was an array, not a list. This threw me away because Foo.findAllByBarInList( bars )
returned my Foo
objects just fine, only when I tried to collect the identifiers did it fail. Now I do bars
with tokenize , and all is well.
source share