java.lang.ClassCastException: com.mongodb.BasicDBObject cannot be cast to com.mongodb.BasicDBList

Spring JIRA | Harlan Iverson | 5 years ago
  1. 0

    While upgrading from M5 to GA I started getting this error in my tests: {noformat} java.lang.ClassCastException: com.mongodb.BasicDBObject cannot be cast to com.mongodb.BasicDBList at org.springframework.data.mongodb.core.convert.MappingMongoConverter.writeInternal(MappingMongoConverter.java:324) at org.springframework.data.mongodb.core.convert.MappingMongoConverter.write(MappingMongoConverter.java:294) at org.springframework.data.mongodb.core.convert.MappingMongoConverter.convertToMongoType(MappingMongoConverter.java:850) at org.springframework.data.mongodb.core.QueryMapper.getMappedObject(QueryMapper.java:106) at org.springframework.data.mongodb.core.QueryMapper.getMappedObject(QueryMapper.java:102) at org.springframework.data.mongodb.core.MongoTemplate.doFind(MongoTemplate.java:1259) at org.springframework.data.mongodb.core.MongoTemplate.doFind(MongoTemplate.java:1248) at org.springframework.data.mongodb.core.MongoTemplate.find(MongoTemplate.java:471) at net.emota.together.service.PersonService.createOrUpdateGroupPersons(PersonService.java:372) at net.emota.together.core.itest.service.PersonServiceIT.createOrUpdateGroupPersons(PersonServiceIT.java:303) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44) at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15) at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41) at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20) at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28) at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:74) at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31) at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:82) at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:72) at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:231) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:49) at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191) at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184) at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61) at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70) at org.junit.runners.ParentRunner.run(ParentRunner.java:236) at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:174) at org.apache.maven.surefire.junit4.JUnit4TestSet.execute(JUnit4TestSet.java:53) at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:123) at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:104) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:164) at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:110) at org.apache.maven.surefire.booter.SurefireStarter.invokeProvider(SurefireStarter.java:175) at org.apache.maven.surefire.booter.SurefireStarter.runSuitesInProcessWhenForked(SurefireStarter.java:107) at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:68) {noformat} The query I am using is simple (and involves $in, maybe releated to my previous issue?): {code} { "fbUserId" : { "$in" : [ "88888" , "ABCDE" , "12345"]} } {code}

    Spring JIRA | 5 years ago | Harlan Iverson
    java.lang.ClassCastException: com.mongodb.BasicDBObject cannot be cast to com.mongodb.BasicDBList
  2. 0

    While upgrading from M5 to GA I started getting this error in my tests: {noformat} java.lang.ClassCastException: com.mongodb.BasicDBObject cannot be cast to com.mongodb.BasicDBList at org.springframework.data.mongodb.core.convert.MappingMongoConverter.writeInternal(MappingMongoConverter.java:324) at org.springframework.data.mongodb.core.convert.MappingMongoConverter.write(MappingMongoConverter.java:294) at org.springframework.data.mongodb.core.convert.MappingMongoConverter.convertToMongoType(MappingMongoConverter.java:850) at org.springframework.data.mongodb.core.QueryMapper.getMappedObject(QueryMapper.java:106) at org.springframework.data.mongodb.core.QueryMapper.getMappedObject(QueryMapper.java:102) at org.springframework.data.mongodb.core.MongoTemplate.doFind(MongoTemplate.java:1259) at org.springframework.data.mongodb.core.MongoTemplate.doFind(MongoTemplate.java:1248) at org.springframework.data.mongodb.core.MongoTemplate.find(MongoTemplate.java:471) at net.emota.together.service.PersonService.createOrUpdateGroupPersons(PersonService.java:372) at net.emota.together.core.itest.service.PersonServiceIT.createOrUpdateGroupPersons(PersonServiceIT.java:303) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44) at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15) at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41) at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20) at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28) at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:74) at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31) at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:82) at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:72) at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:231) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:49) at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191) at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184) at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61) at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70) at org.junit.runners.ParentRunner.run(ParentRunner.java:236) at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:174) at org.apache.maven.surefire.junit4.JUnit4TestSet.execute(JUnit4TestSet.java:53) at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:123) at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:104) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:164) at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:110) at org.apache.maven.surefire.booter.SurefireStarter.invokeProvider(SurefireStarter.java:175) at org.apache.maven.surefire.booter.SurefireStarter.runSuitesInProcessWhenForked(SurefireStarter.java:107) at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:68) {noformat} The query I am using is simple (and involves $in, maybe releated to my previous issue?): {code} { "fbUserId" : { "$in" : [ "88888" , "ABCDE" , "12345"]} } {code}

    Spring JIRA | 5 years ago | Harlan Iverson
    java.lang.ClassCastException: com.mongodb.BasicDBObject cannot be cast to com.mongodb.BasicDBList
  3. 0

    When I create a query on document {{_id}} with {{$in}} operator and reuse that query to do another search i get {{ClassCastException}}. Query creation: {code:java} query.addCriteria(Criteria.where("_id").in(signedPetitionIds)); {code} Reusing query (as a filterQuery argument): {code:java} private Page<PetitionHeader> findPetitionHeaders(Pageable pageable, Query filterQuery, Sort sort) { long count = mongoOp.count(filterQuery, PetitionHeader.class); filterQuery.with(pageable); filterQuery.with(sort); List<PetitionHeader> headers = mongoOp.find(filterQuery, PetitionHeader.class); return new PageImpl<PetitionHeader>(headers, pageable, count); } {code} Stacktrace: {noformat} java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to java.lang.Iterable at org.springframework.data.mongodb.core.convert.QueryMapper.getMappedValue(QueryMapper.java:159) ~[spring-data-mongodb-1.2.1.RELEASE.jar:na] at org.springframework.data.mongodb.core.convert.QueryMapper.getMappedObject(QueryMapper.java:90) ~[spring-data-mongodb-1.2.1.RELEASE.jar:na] at org.springframework.data.mongodb.core.convert.QueryMapper.getMappedKeyword(QueryMapper.java:112) ~[spring-data-mongodb-1.2.1.RELEASE.jar:na] at org.springframework.data.mongodb.core.convert.QueryMapper.getMappedObject(QueryMapper.java:79) ~[spring-data-mongodb-1.2.1.RELEASE.jar:na] at org.springframework.data.mongodb.core.MongoTemplate.doFind(MongoTemplate.java:1337) ~[spring-data-mongodb-1.2.1.RELEASE.jar:na] at org.springframework.data.mongodb.core.MongoTemplate.doFind(MongoTemplate.java:1323) ~[spring-data-mongodb-1.2.1.RELEASE.jar:na] at org.springframework.data.mongodb.core.MongoTemplate.find(MongoTemplate.java:495) ~[spring-data-mongodb-1.2.1.RELEASE.jar:na] at org.springframework.data.mongodb.core.MongoTemplate.find(MongoTemplate.java:486) ~[spring-data-mongodb-1.2.1.RELEASE.jar:na] {noformat} Object returned by {{valueDbo.get(inKey)}} (in line 159) is of type {{Object[]}}.

    Spring JIRA | 4 years ago | Paweł Mendelski
    java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to java.lang.Iterable
  4. Speed up your debug routine!

    Automated exception search integrated into your IDE

  5. 0

    When I create a query on document {{_id}} with {{$in}} operator and reuse that query to do another search i get {{ClassCastException}}. Query creation: {code:java} query.addCriteria(Criteria.where("_id").in(signedPetitionIds)); {code} Reusing query (as a filterQuery argument): {code:java} private Page<PetitionHeader> findPetitionHeaders(Pageable pageable, Query filterQuery, Sort sort) { long count = mongoOp.count(filterQuery, PetitionHeader.class); filterQuery.with(pageable); filterQuery.with(sort); List<PetitionHeader> headers = mongoOp.find(filterQuery, PetitionHeader.class); return new PageImpl<PetitionHeader>(headers, pageable, count); } {code} Stacktrace: {noformat} java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to java.lang.Iterable at org.springframework.data.mongodb.core.convert.QueryMapper.getMappedValue(QueryMapper.java:159) ~[spring-data-mongodb-1.2.1.RELEASE.jar:na] at org.springframework.data.mongodb.core.convert.QueryMapper.getMappedObject(QueryMapper.java:90) ~[spring-data-mongodb-1.2.1.RELEASE.jar:na] at org.springframework.data.mongodb.core.convert.QueryMapper.getMappedKeyword(QueryMapper.java:112) ~[spring-data-mongodb-1.2.1.RELEASE.jar:na] at org.springframework.data.mongodb.core.convert.QueryMapper.getMappedObject(QueryMapper.java:79) ~[spring-data-mongodb-1.2.1.RELEASE.jar:na] at org.springframework.data.mongodb.core.MongoTemplate.doFind(MongoTemplate.java:1337) ~[spring-data-mongodb-1.2.1.RELEASE.jar:na] at org.springframework.data.mongodb.core.MongoTemplate.doFind(MongoTemplate.java:1323) ~[spring-data-mongodb-1.2.1.RELEASE.jar:na] at org.springframework.data.mongodb.core.MongoTemplate.find(MongoTemplate.java:495) ~[spring-data-mongodb-1.2.1.RELEASE.jar:na] at org.springframework.data.mongodb.core.MongoTemplate.find(MongoTemplate.java:486) ~[spring-data-mongodb-1.2.1.RELEASE.jar:na] {noformat} Object returned by {{valueDbo.get(inKey)}} (in line 159) is of type {{Object[]}}.

    Spring JIRA | 4 years ago | Paweł Mendelski
    java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to java.lang.Iterable
  6. 0

    Spring Data MongoDB - class cast exception when persisting a List

    Stack Overflow | 1 year ago | FIV
    java.lang.ClassCastException: com.mongodb.BasicDBObject cannot be cast to com.mongodb.BasicDBList

    Not finding the right solution?
    Take a tour to get the most out of Samebug.

    Tired of useless tips?

    Automated exception search integrated into your IDE

    Root Cause Analysis

    1. java.lang.ClassCastException

      com.mongodb.BasicDBObject cannot be cast to com.mongodb.BasicDBList

      at org.springframework.data.mongodb.core.convert.MappingMongoConverter.writeInternal()
    2. Spring Data MongoDB - Core
      MongoTemplate.find
      1. org.springframework.data.mongodb.core.convert.MappingMongoConverter.writeInternal(MappingMongoConverter.java:324)
      2. org.springframework.data.mongodb.core.convert.MappingMongoConverter.write(MappingMongoConverter.java:294)
      3. org.springframework.data.mongodb.core.convert.MappingMongoConverter.convertToMongoType(MappingMongoConverter.java:850)
      4. org.springframework.data.mongodb.core.QueryMapper.getMappedObject(QueryMapper.java:106)
      5. org.springframework.data.mongodb.core.QueryMapper.getMappedObject(QueryMapper.java:102)
      6. org.springframework.data.mongodb.core.MongoTemplate.doFind(MongoTemplate.java:1259)
      7. org.springframework.data.mongodb.core.MongoTemplate.doFind(MongoTemplate.java:1248)
      8. org.springframework.data.mongodb.core.MongoTemplate.find(MongoTemplate.java:471)
      8 frames
    3. net.emota.together
      PersonServiceIT.createOrUpdateGroupPersons
      1. net.emota.together.service.PersonService.createOrUpdateGroupPersons(PersonService.java:372)
      2. net.emota.together.core.itest.service.PersonServiceIT.createOrUpdateGroupPersons(PersonServiceIT.java:303)
      2 frames
    4. Java RT
      Method.invoke
      1. sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      2. sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      3. sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      4. java.lang.reflect.Method.invoke(Method.java:597)
      4 frames
    5. JUnit
      RunBefores.evaluate
      1. org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
      2. org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
      3. org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
      4. org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
      5. org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
      5 frames
    6. Spring TestContext
      RunBeforeTestMethodCallbacks.evaluate
      1. org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:74)
      1 frame
    7. JUnit
      RunAfters.evaluate
      1. org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
      1 frame
    8. Spring TestContext
      SpringJUnit4ClassRunner.runChild
      1. org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:82)
      2. org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:72)
      3. org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:231)
      3 frames
    9. JUnit
      ParentRunner$2.evaluate
      1. org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:49)
      2. org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
      3. org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
      4. org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
      5. org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
      6. org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
      6 frames
    10. Spring TestContext
      RunAfterTestClassCallbacks.evaluate
      1. org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
      2. org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)
      2 frames
    11. JUnit
      ParentRunner.run
      1. org.junit.runners.ParentRunner.run(ParentRunner.java:236)
      1 frame
    12. Spring TestContext
      SpringJUnit4ClassRunner.run
      1. org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:174)
      1 frame
    13. JUnit4 Provider
      JUnit4Provider.invoke
      1. org.apache.maven.surefire.junit4.JUnit4TestSet.execute(JUnit4TestSet.java:53)
      2. org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:123)
      3. org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:104)
      3 frames
    14. Java RT
      Method.invoke
      1. sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      2. sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      3. sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      4. java.lang.reflect.Method.invoke(Method.java:597)
      4 frames
    15. SureFire
      ForkedBooter.main
      1. org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:164)
      2. org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:110)
      3. org.apache.maven.surefire.booter.SurefireStarter.invokeProvider(SurefireStarter.java:175)
      4. org.apache.maven.surefire.booter.SurefireStarter.runSuitesInProcessWhenForked(SurefireStarter.java:107)
      5. org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:68)
      5 frames