java.lang.IllegalArgumentException: can't serialize class MatchAfterProjectIssue$Age

Spring JIRA | Konstantin Lutovich | 3 years ago
  1. 0

    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!

    Spring JIRA | 3 years ago | Konstantin Lutovich
    java.lang.IllegalArgumentException: can't serialize class MatchAfterProjectIssue$Age
  2. 0

    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!

    Spring JIRA | 3 years ago | Konstantin Lutovich
    java.lang.IllegalArgumentException: can't serialize class MatchAfterProjectIssue$Age
  3. 0

    Spring Data MongoDB NearQuery EnumList IllegalArgumentException

    Stack Overflow | 2 years ago
    java.lang.IllegalArgumentException: can't serialize class com.testarea.model.enums.TestEnum
  4. Speed up your debug routine!

    Automated exception search integrated into your IDE

  5. 0

    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}

    Spring JIRA | 2 years ago | Thomas Darimont
    java.lang.IllegalArgumentException: can't serialize class org.springframework.data.geo.Point
  6. 0

    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}

    Spring JIRA | 2 years ago | Thomas Darimont
    java.lang.IllegalArgumentException: can't serialize class org.springframework.data.geo.Point

    1 unregistered visitors
    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.IllegalArgumentException

      can't serialize class MatchAfterProjectIssue$Age

      at org.bson.BasicBSONEncoder._putObjectField()
    2. MongoDB Java Driver
      DB.command
      1. org.bson.BasicBSONEncoder._putObjectField(BasicBSONEncoder.java:272)
      2. org.bson.BasicBSONEncoder.putObject(BasicBSONEncoder.java:173)
      3. org.bson.BasicBSONEncoder._putObjectField(BasicBSONEncoder.java:228)
      4. org.bson.BasicBSONEncoder.putObject(BasicBSONEncoder.java:173)
      5. org.bson.BasicBSONEncoder._putObjectField(BasicBSONEncoder.java:228)
      6. org.bson.BasicBSONEncoder.putIterable(BasicBSONEncoder.java:297)
      7. org.bson.BasicBSONEncoder._putObjectField(BasicBSONEncoder.java:236)
      8. org.bson.BasicBSONEncoder.putObject(BasicBSONEncoder.java:173)
      9. org.bson.BasicBSONEncoder.putObject(BasicBSONEncoder.java:119)
      10. com.mongodb.DefaultDBEncoder.writeObject(DefaultDBEncoder.java:27)
      11. com.mongodb.OutMessage.putObject(OutMessage.java:289)
      12. com.mongodb.OutMessage.writeQuery(OutMessage.java:211)
      13. com.mongodb.OutMessage.query(OutMessage.java:84)
      14. com.mongodb.DBApiLayer$MyCollection.__find(DBApiLayer.java:285)
      15. com.mongodb.DB.command(DB.java:262)
      16. com.mongodb.DB.command(DB.java:244)
      17. com.mongodb.DB.command(DB.java:301)
      18. com.mongodb.DB.command(DB.java:199)
      18 frames
    3. Spring Data MongoDB - Core
      MongoTemplate.aggregate
      1. org.springframework.data.mongodb.core.MongoTemplate$1.doInDB(MongoTemplate.java:323)
      2. org.springframework.data.mongodb.core.MongoTemplate$1.doInDB(MongoTemplate.java:321)
      3. org.springframework.data.mongodb.core.MongoTemplate.execute(MongoTemplate.java:391)
      4. org.springframework.data.mongodb.core.MongoTemplate.executeCommand(MongoTemplate.java:321)
      5. org.springframework.data.mongodb.core.MongoTemplate.aggregate(MongoTemplate.java:1328)
      6. org.springframework.data.mongodb.core.MongoTemplate.aggregate(MongoTemplate.java:1305)
      6 frames