java.lang.IllegalArgumentException

There are no available Samebug tips for this exception. Do you have an idea how to solve this issue? A short tip would help users who saw this issue last week.

  • I have an aggregation pipeline with two stages (match, project) and a custom converter for the entity being matched by. When {{MongoTemplate#aggregate}} is called with {{Aggregation.newAggregation(match, project)}} everything works as expected, but when it is called with {{Aggregation.newAggregation(project, match)}} appears the following exception: {code} Exception in thread "main" java.lang.IllegalArgumentException: can't serialize class MatchAfterProjectIssue$Age at org.bson.BasicBSONEncoder._putObjectField(BasicBSONEncoder.java:272) at org.bson.BasicBSONEncoder.putObject(BasicBSONEncoder.java:173) at org.bson.BasicBSONEncoder._putObjectField(BasicBSONEncoder.java:228) at org.bson.BasicBSONEncoder.putObject(BasicBSONEncoder.java:173) at org.bson.BasicBSONEncoder._putObjectField(BasicBSONEncoder.java:228) at org.bson.BasicBSONEncoder.putIterable(BasicBSONEncoder.java:297) at org.bson.BasicBSONEncoder._putObjectField(BasicBSONEncoder.java:236) at org.bson.BasicBSONEncoder.putObject(BasicBSONEncoder.java:173) at org.bson.BasicBSONEncoder.putObject(BasicBSONEncoder.java:119) at com.mongodb.DefaultDBEncoder.writeObject(DefaultDBEncoder.java:27) at com.mongodb.OutMessage.putObject(OutMessage.java:289) at com.mongodb.OutMessage.writeQuery(OutMessage.java:211) at com.mongodb.OutMessage.query(OutMessage.java:84) at com.mongodb.DBApiLayer$MyCollection.__find(DBApiLayer.java:285) at com.mongodb.DB.command(DB.java:262) at com.mongodb.DB.command(DB.java:244) at com.mongodb.DB.command(DB.java:301) at com.mongodb.DB.command(DB.java:199) at org.springframework.data.mongodb.core.MongoTemplate$1.doInDB(MongoTemplate.java:323) at org.springframework.data.mongodb.core.MongoTemplate$1.doInDB(MongoTemplate.java:321) at org.springframework.data.mongodb.core.MongoTemplate.execute(MongoTemplate.java:391) at org.springframework.data.mongodb.core.MongoTemplate.executeCommand(MongoTemplate.java:321) at org.springframework.data.mongodb.core.MongoTemplate.aggregate(MongoTemplate.java:1328) at org.springframework.data.mongodb.core.MongoTemplate.aggregate(MongoTemplate.java:1305) {code} Looks like this happens because the project stage, being first, sets the {{AggregationOperationContext}} to the newly created {{ExposedFieldsAggregationOperationContext}} which does not use custom converters. When match stage goes first it uses the proper {{AggregationOperationContext}} - {{TypeBasedAggregationOperationContext}}. The relevant code is {{Aggregation#toDbObject}} method. Attached gist and file contains code to reproduce the problem. Thank you!
    via by Konstantin Lutovich,
  • I have an aggregation pipeline with two stages (match, project) and a custom converter for the entity being matched by. When {{MongoTemplate#aggregate}} is called with {{Aggregation.newAggregation(match, project)}} everything works as expected, but when it is called with {{Aggregation.newAggregation(project, match)}} appears the following exception: {code} Exception in thread "main" java.lang.IllegalArgumentException: can't serialize class MatchAfterProjectIssue$Age at org.bson.BasicBSONEncoder._putObjectField(BasicBSONEncoder.java:272) at org.bson.BasicBSONEncoder.putObject(BasicBSONEncoder.java:173) at org.bson.BasicBSONEncoder._putObjectField(BasicBSONEncoder.java:228) at org.bson.BasicBSONEncoder.putObject(BasicBSONEncoder.java:173) at org.bson.BasicBSONEncoder._putObjectField(BasicBSONEncoder.java:228) at org.bson.BasicBSONEncoder.putIterable(BasicBSONEncoder.java:297) at org.bson.BasicBSONEncoder._putObjectField(BasicBSONEncoder.java:236) at org.bson.BasicBSONEncoder.putObject(BasicBSONEncoder.java:173) at org.bson.BasicBSONEncoder.putObject(BasicBSONEncoder.java:119) at com.mongodb.DefaultDBEncoder.writeObject(DefaultDBEncoder.java:27) at com.mongodb.OutMessage.putObject(OutMessage.java:289) at com.mongodb.OutMessage.writeQuery(OutMessage.java:211) at com.mongodb.OutMessage.query(OutMessage.java:84) at com.mongodb.DBApiLayer$MyCollection.__find(DBApiLayer.java:285) at com.mongodb.DB.command(DB.java:262) at com.mongodb.DB.command(DB.java:244) at com.mongodb.DB.command(DB.java:301) at com.mongodb.DB.command(DB.java:199) at org.springframework.data.mongodb.core.MongoTemplate$1.doInDB(MongoTemplate.java:323) at org.springframework.data.mongodb.core.MongoTemplate$1.doInDB(MongoTemplate.java:321) at org.springframework.data.mongodb.core.MongoTemplate.execute(MongoTemplate.java:391) at org.springframework.data.mongodb.core.MongoTemplate.executeCommand(MongoTemplate.java:321) at org.springframework.data.mongodb.core.MongoTemplate.aggregate(MongoTemplate.java:1328) at org.springframework.data.mongodb.core.MongoTemplate.aggregate(MongoTemplate.java:1305) {code} Looks like this happens because the project stage, being first, sets the {{AggregationOperationContext}} to the newly created {{ExposedFieldsAggregationOperationContext}} which does not use custom converters. When match stage goes first it uses the proper {{AggregationOperationContext}} - {{TypeBasedAggregationOperationContext}}. The relevant code is {{Aggregation#toDbObject}} method. Attached gist and file contains code to reproduce the problem. Thank you!
    via by Konstantin Lutovich,
  • It seems that the point given to {{Criteria.nearSphere}} isn't passed through the mapping infrastructure. {code:java} @Test public void serializePoinInCriteriaNearSphere() throws Exception { Point p = new Point(1.0, 2.0); Aggregation agg = newAggregation( match(new Criteria().andOperator(Criteria.where("eventTime").gte(1), Criteria.where("location").nearSphere(p) .maxDistance(5.0))), sort(Direction.DESC, "vanId", "eventTime"), group("vanId").first(Aggregation.ROOT).as("first")); mongoTemplate.aggregate(agg, "foo", DBObject.class); } {code} Produces: {code} java.lang.IllegalArgumentException: can't serialize class org.springframework.data.geo.Point at org.bson.BasicBSONEncoder._putObjectField(BasicBSONEncoder.java:299) at org.bson.BasicBSONEncoder.putObject(BasicBSONEncoder.java:194) at org.bson.BasicBSONEncoder._putObjectField(BasicBSONEncoder.java:255) at org.bson.BasicBSONEncoder.putObject(BasicBSONEncoder.java:194) at org.bson.BasicBSONEncoder._putObjectField(BasicBSONEncoder.java:255) at org.bson.BasicBSONEncoder.putObject(BasicBSONEncoder.java:208) at org.bson.BasicBSONEncoder._putObjectField(BasicBSONEncoder.java:255) at org.bson.BasicBSONEncoder.putObject(BasicBSONEncoder.java:194) at org.bson.BasicBSONEncoder._putObjectField(BasicBSONEncoder.java:255) at org.bson.BasicBSONEncoder.putObject(BasicBSONEncoder.java:194) at org.bson.BasicBSONEncoder._putObjectField(BasicBSONEncoder.java:255) at org.bson.BasicBSONEncoder.putIterable(BasicBSONEncoder.java:324) at org.bson.BasicBSONEncoder._putObjectField(BasicBSONEncoder.java:263) at org.bson.BasicBSONEncoder.putObject(BasicBSONEncoder.java:194) at org.bson.BasicBSONEncoder.putObject(BasicBSONEncoder.java:136) at com.mongodb.DefaultDBEncoder.writeObject(DefaultDBEncoder.java:36) at com.mongodb.OutMessage.putObject(OutMessage.java:289) at com.mongodb.OutMessage.writeQuery(OutMessage.java:211) at com.mongodb.OutMessage.query(OutMessage.java:86) at com.mongodb.DBCollectionImpl.find(DBCollectionImpl.java:81) at com.mongodb.DB.command(DB.java:320) at com.mongodb.DB.command(DB.java:299) at com.mongodb.DB.command(DB.java:374) at com.mongodb.DB.command(DB.java:246) at org.springframework.data.mongodb.core.MongoTemplate$2.doInDB(MongoTemplate.java:357) at org.springframework.data.mongodb.core.MongoTemplate$2.doInDB(MongoTemplate.java:1) at org.springframework.data.mongodb.core.MongoTemplate.execute(MongoTemplate.java:442) at org.springframework.data.mongodb.core.MongoTemplate.executeCommand(MongoTemplate.java:355) at org.springframework.data.mongodb.core.MongoTemplate.aggregate(MongoTemplate.java:1497) at org.springframework.data.mongodb.core.MongoTemplate.aggregate(MongoTemplate.java:1432) at org.springframework.data.mongodb.core.aggregation.AggregationTests.serializePoinInCriteriaNearSphere(AggregationTests.java:1083) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:497) at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50) at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47) at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17) at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26) at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:73) at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27) at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:82) at org.junit.rules.ExpectedException$ExpectedExceptionStatement.evaluate(ExpectedException.java:239) at org.junit.rules.RunRules.evaluate(RunRules.java:20) at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:73) at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325) at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:224) at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:83) at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288) at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268) at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61) at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:68) at org.junit.runners.ParentRunner.run(ParentRunner.java:363) at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:163) at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50) at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192) {code}
    via by Thomas Darimont,
  • It seems that the point given to {{Criteria.nearSphere}} isn't passed through the mapping infrastructure. {code:java} @Test public void serializePoinInCriteriaNearSphere() throws Exception { Point p = new Point(1.0, 2.0); Aggregation agg = newAggregation( match(new Criteria().andOperator(Criteria.where("eventTime").gte(1), Criteria.where("location").nearSphere(p) .maxDistance(5.0))), sort(Direction.DESC, "vanId", "eventTime"), group("vanId").first(Aggregation.ROOT).as("first")); mongoTemplate.aggregate(agg, "foo", DBObject.class); } {code} Produces: {code} java.lang.IllegalArgumentException: can't serialize class org.springframework.data.geo.Point at org.bson.BasicBSONEncoder._putObjectField(BasicBSONEncoder.java:299) at org.bson.BasicBSONEncoder.putObject(BasicBSONEncoder.java:194) at org.bson.BasicBSONEncoder._putObjectField(BasicBSONEncoder.java:255) at org.bson.BasicBSONEncoder.putObject(BasicBSONEncoder.java:194) at org.bson.BasicBSONEncoder._putObjectField(BasicBSONEncoder.java:255) at org.bson.BasicBSONEncoder.putObject(BasicBSONEncoder.java:208) at org.bson.BasicBSONEncoder._putObjectField(BasicBSONEncoder.java:255) at org.bson.BasicBSONEncoder.putObject(BasicBSONEncoder.java:194) at org.bson.BasicBSONEncoder._putObjectField(BasicBSONEncoder.java:255) at org.bson.BasicBSONEncoder.putObject(BasicBSONEncoder.java:194) at org.bson.BasicBSONEncoder._putObjectField(BasicBSONEncoder.java:255) at org.bson.BasicBSONEncoder.putIterable(BasicBSONEncoder.java:324) at org.bson.BasicBSONEncoder._putObjectField(BasicBSONEncoder.java:263) at org.bson.BasicBSONEncoder.putObject(BasicBSONEncoder.java:194) at org.bson.BasicBSONEncoder.putObject(BasicBSONEncoder.java:136) at com.mongodb.DefaultDBEncoder.writeObject(DefaultDBEncoder.java:36) at com.mongodb.OutMessage.putObject(OutMessage.java:289) at com.mongodb.OutMessage.writeQuery(OutMessage.java:211) at com.mongodb.OutMessage.query(OutMessage.java:86) at com.mongodb.DBCollectionImpl.find(DBCollectionImpl.java:81) at com.mongodb.DB.command(DB.java:320) at com.mongodb.DB.command(DB.java:299) at com.mongodb.DB.command(DB.java:374) at com.mongodb.DB.command(DB.java:246) at org.springframework.data.mongodb.core.MongoTemplate$2.doInDB(MongoTemplate.java:357) at org.springframework.data.mongodb.core.MongoTemplate$2.doInDB(MongoTemplate.java:1) at org.springframework.data.mongodb.core.MongoTemplate.execute(MongoTemplate.java:442) at org.springframework.data.mongodb.core.MongoTemplate.executeCommand(MongoTemplate.java:355) at org.springframework.data.mongodb.core.MongoTemplate.aggregate(MongoTemplate.java:1497) at org.springframework.data.mongodb.core.MongoTemplate.aggregate(MongoTemplate.java:1432) at org.springframework.data.mongodb.core.aggregation.AggregationTests.serializePoinInCriteriaNearSphere(AggregationTests.java:1083) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:497) at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50) at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47) at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17) at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26) at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:73) at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27) at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:82) at org.junit.rules.ExpectedException$ExpectedExceptionStatement.evaluate(ExpectedException.java:239) at org.junit.rules.RunRules.evaluate(RunRules.java:20) at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:73) at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325) at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:224) at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:83) at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288) at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268) at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61) at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:68) at org.junit.runners.ParentRunner.run(ParentRunner.java:363) at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:163) at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50) at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192) {code}
    via by Thomas Darimont,
  • Alert check errors
    via GitHub by lennartkoopmann
    ,
    • java.lang.IllegalArgumentException: can't serialize class MatchAfterProjectIssue$Age at org.bson.BasicBSONEncoder._putObjectField(BasicBSONEncoder.java:272) at org.bson.BasicBSONEncoder.putObject(BasicBSONEncoder.java:173) at org.bson.BasicBSONEncoder._putObjectField(BasicBSONEncoder.java:228) at org.bson.BasicBSONEncoder.putObject(BasicBSONEncoder.java:173) at org.bson.BasicBSONEncoder._putObjectField(BasicBSONEncoder.java:228) at org.bson.BasicBSONEncoder.putIterable(BasicBSONEncoder.java:297) at org.bson.BasicBSONEncoder._putObjectField(BasicBSONEncoder.java:236) at org.bson.BasicBSONEncoder.putObject(BasicBSONEncoder.java:173) at org.bson.BasicBSONEncoder.putObject(BasicBSONEncoder.java:119) at com.mongodb.DefaultDBEncoder.writeObject(DefaultDBEncoder.java:27) at com.mongodb.OutMessage.putObject(OutMessage.java:289) at com.mongodb.OutMessage.writeQuery(OutMessage.java:211) at com.mongodb.OutMessage.query(OutMessage.java:84) at com.mongodb.DBApiLayer$MyCollection.__find(DBApiLayer.java:285) at com.mongodb.DB.command(DB.java:262) at com.mongodb.DB.command(DB.java:244) at com.mongodb.DB.command(DB.java:301) at com.mongodb.DB.command(DB.java:199) at org.springframework.data.mongodb.core.MongoTemplate$1.doInDB(MongoTemplate.java:323) at org.springframework.data.mongodb.core.MongoTemplate$1.doInDB(MongoTemplate.java:321) at org.springframework.data.mongodb.core.MongoTemplate.execute(MongoTemplate.java:391) at org.springframework.data.mongodb.core.MongoTemplate.executeCommand(MongoTemplate.java:321) at org.springframework.data.mongodb.core.MongoTemplate.aggregate(MongoTemplate.java:1328) at org.springframework.data.mongodb.core.MongoTemplate.aggregate(MongoTemplate.java:1305)

    Users with the same issue

    Unknown visitor1 times, last one,
    rp
    1 times, last one,
    Unknown visitor1 times, last one,
    Unknown visitor1 times, last one,
    Unknown visitor1 times, last one,