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 get an "IllegalArgumentException: can't serialize class" every time I use an {{enum}} or {{LocalDateTime}} (and problably other java.time classes) in a {{Criteria}} that is then handed to a distinct query. Since the same is working with simple find queries I guess it's a bug around using {{Criteria}} with distinct. Here is a sample code: {code:java} public List<BasicDBObject> retrieveDistinctDocuments(LocalDateTime from, LocalDateTime to) { Query query = new Query(Criteria.where(FIELD_TIME).gte(from).lte(to)); return mongoTemplate.getCollection(COLLECTION_NAME).distinct(FIELD_NAME, query.getQueryObject()); } {code} See stacktrace: {noformat} java.lang.IllegalArgumentException: can't serialize class java.time.LocalDateTime 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: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.DBCollection.distinct(DBCollection.java:1475) at com.mongodb.DBCollection.distinct(DBCollection.java:1455) {noformat}
    via by Balazs Peterfi,
  • I get an "IllegalArgumentException: can't serialize class" every time I use an {{enum}} or {{LocalDateTime}} (and problably other java.time classes) in a {{Criteria}} that is then handed to a distinct query. Since the same is working with simple find queries I guess it's a bug around using {{Criteria}} with distinct. Here is a sample code: {code:java} public List<BasicDBObject> retrieveDistinctDocuments(LocalDateTime from, LocalDateTime to) { Query query = new Query(Criteria.where(FIELD_TIME).gte(from).lte(to)); return mongoTemplate.getCollection(COLLECTION_NAME).distinct(FIELD_NAME, query.getQueryObject()); } {code} See stacktrace: {noformat} java.lang.IllegalArgumentException: can't serialize class java.time.LocalDateTime 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: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.DBCollection.distinct(DBCollection.java:1475) at com.mongodb.DBCollection.distinct(DBCollection.java:1455) {noformat}
    via by Balazs Peterfi,
  • Exception Java mongo client 2.4
    via by sagar,
  • Exception in Mongo java client 2.4
    via Stack Overflow by Sagar Varpe
    ,
  • Alert check errors
    via GitHub by lennartkoopmann
    ,
    • java.lang.IllegalArgumentException: can't serialize class java.time.LocalDateTime 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: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.DBCollection.distinct(DBCollection.java:1475) at com.mongodb.DBCollection.distinct(DBCollection.java:1455)

    Users with the same issue

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