java.lang.IllegalArgumentException: can't serialize class java.time.LocalDateTime

Spring JIRA | Balazs Peterfi | 8 months ago
  1. 0

    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}

    Spring JIRA | 8 months ago | Balazs Peterfi
    java.lang.IllegalArgumentException: can't serialize class java.time.LocalDateTime
  2. 0

    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}

    Spring JIRA | 8 months ago | Balazs Peterfi
    java.lang.IllegalArgumentException: can't serialize class java.time.LocalDateTime
  3. 0

    Exception Java mongo client 2.4

    Google Groups | 6 years ago | sagar
    java.lang.IllegalArgumentException: 'ok' should never be null...
  4. Speed up your debug routine!

    Automated exception search integrated into your IDE

  5. 0

    [mongodb-user] Exception Java mongo client 2.4

    Google Groups | 6 years ago | sagar
    java.lang.IllegalArgumentException: 'ok' should never be null...
  6. 0

    Exception in Mongo java client 2.4

    Stack Overflow | 6 years ago | Sagar Varpe
    java.lang.IllegalArgumentException: 'ok' should never be null...

    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 java.time.LocalDateTime

      at org.bson.BasicBSONEncoder._putObjectField()
    2. MongoDB Java Driver
      DBCollection.distinct
      1. org.bson.BasicBSONEncoder._putObjectField(BasicBSONEncoder.java:299)
      2. org.bson.BasicBSONEncoder.putObject(BasicBSONEncoder.java:194)
      3. org.bson.BasicBSONEncoder._putObjectField(BasicBSONEncoder.java:255)
      4. org.bson.BasicBSONEncoder.putObject(BasicBSONEncoder.java:194)
      5. org.bson.BasicBSONEncoder._putObjectField(BasicBSONEncoder.java:255)
      6. org.bson.BasicBSONEncoder.putObject(BasicBSONEncoder.java:194)
      7. org.bson.BasicBSONEncoder.putObject(BasicBSONEncoder.java:136)
      8. com.mongodb.DefaultDBEncoder.writeObject(DefaultDBEncoder.java:36)
      9. com.mongodb.OutMessage.putObject(OutMessage.java:289)
      10. com.mongodb.OutMessage.writeQuery(OutMessage.java:211)
      11. com.mongodb.OutMessage.query(OutMessage.java:86)
      12. com.mongodb.DBCollectionImpl.find(DBCollectionImpl.java:81)
      13. com.mongodb.DB.command(DB.java:320)
      14. com.mongodb.DB.command(DB.java:299)
      15. com.mongodb.DBCollection.distinct(DBCollection.java:1475)
      16. com.mongodb.DBCollection.distinct(DBCollection.java:1455)
      16 frames