poiati / gmongo

A Groovy wrapper to the mongodb Java driver
http://blog.paulopoiati.com/2010/06/20/gmongo-0-5-released/
Apache License 2.0
182 stars 44 forks source link

Add support for java.util.Collections$SingletonList #24

Open danpolites opened 9 years ago

danpolites commented 9 years ago

An UnsupportedOperationException is thrown when using a SingletonList in an '$in' query when using the Grails Mongo Gorm plugin. Grails has this odd behavior where you get a SingletonList when converting an http parameter to a list (params.list('userIds')) on a one item parameter. In the cases where you have multiple items in the parameter you get an ArrayList, which works fine with gmongo. The work around is to use a mutable list or cast the value to a string array.

Here is an example of a Mongo Gorm call that would fail if the collection is a SingletonList User.collection.find([_id: ['$in': singletonListOfIds]])

java.lang.UnsupportedOperationException
    at java.util.AbstractList.set(AbstractList.java:132)
    at com.gmongo.internal.Patcher$__converAllCharSeqToString_closure2_closure4.doCall(Patcher.groovy:89)
    at com.gmongo.internal.Patcher$__converAllCharSeqToString_closure2.doCall(Patcher.groovy:87)
    at com.gmongo.internal.Patcher._converAllCharSeqToString(Patcher.groovy:84)
    at com.gmongo.internal.Patcher$__converAllCharSeqToString_closure2.doCall(Patcher.groovy:102)
    at com.gmongo.internal.Patcher._converAllCharSeqToString(Patcher.groovy:84)
    at com.gmongo.internal.Patcher$__converAllCharSeqToString_closure2_closure4.doCall(Patcher.groovy:93)
    at com.gmongo.internal.Patcher$__converAllCharSeqToString_closure2.doCall(Patcher.groovy:87)
    at com.gmongo.internal.Patcher._converAllCharSeqToString(Patcher.groovy:84)
    at com.gmongo.internal.Patcher$__converAllCharSeqToString_closure2.doCall(Patcher.groovy:102)
    at com.gmongo.internal.Patcher._converAllCharSeqToString(Patcher.groovy:84)
    at com.gmongo.internal.Patcher._convert(Patcher.groovy:73)
    at com.gmongo.internal.Patcher._convert(Patcher.groovy:69)
    at com.gmongo.internal.Patcher$__patchInternal_closure1.doCall(Patcher.groovy:32)