java.lang.RuntimeException

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 am not being lazy, but i think this quote from the code that i attach can describe better : {code:java} List<MyNested> someValues = Arrays.asList(new MyNested("my"), new MyNested("name"), new MyNested("is")); MyNested[] array = new MyNested[someValues.size()]; this.ops.updateFirst( Query.query(Criteria.where("id").is("testId")), new Update().pushAll("nestedList", someValues.toArray(array)), // fails with exception // new Update().set("nestedList", someValues.toArray()), // this works fine ! // new Update().set("myNested", new MyNested("my")), // this works fine ! COLLECTION_NAME); {code} Using {{pushAll(…)}} will results in exception, and also i notice that the converter's debugging message is not displayed. And the error message seems to say that it can't serialize my custom class where it should be the dbObject that should be serialized. Here's the exception trace : {noformat} Exception in thread "main" java.lang.RuntimeException: json can't serialize type : class kam.albert.domain.test.post.TestConverterThatFails$MyNested at com.mongodb.util.JSON.serialize(JSON.java:261) at com.mongodb.util.JSON.serialize(JSON.java:210) at com.mongodb.util.JSON.serialize(JSON.java:141) at com.mongodb.util.JSON.serialize(JSON.java:141) at com.mongodb.util.JSON.serialize(JSON.java:58) at com.mongodb.BasicDBObject.toString(BasicDBObject.java:84) at java.lang.String.valueOf(Unknown Source) at java.lang.StringBuilder.append(Unknown Source) at org.springframework.data.mongodb.core.MongoTemplate$12.doInCollection(MongoTemplate.java:840) at org.springframework.data.mongodb.core.MongoTemplate$12.doInCollection(MongoTemplate.java:826) at org.springframework.data.mongodb.core.MongoTemplate.execute(MongoTemplate.java:368) at org.springframework.data.mongodb.core.MongoTemplate.doUpdate(MongoTemplate.java:826) at org.springframework.data.mongodb.core.MongoTemplate.updateFirst(MongoTemplate.java:812) at kam.albert.domain.test.post.TestConverterThatFails.test(TestConverterThatFails.java:50) at kam.albert.domain.test.post.TestConverterThatFails.main(TestConverterThatFails.java:30) {noformat}
    via by albert kam,
  • I am not being lazy, but i think this quote from the code that i attach can describe better : {code:java} List<MyNested> someValues = Arrays.asList(new MyNested("my"), new MyNested("name"), new MyNested("is")); MyNested[] array = new MyNested[someValues.size()]; this.ops.updateFirst( Query.query(Criteria.where("id").is("testId")), new Update().pushAll("nestedList", someValues.toArray(array)), // fails with exception // new Update().set("nestedList", someValues.toArray()), // this works fine ! // new Update().set("myNested", new MyNested("my")), // this works fine ! COLLECTION_NAME); {code} Using {{pushAll(…)}} will results in exception, and also i notice that the converter's debugging message is not displayed. And the error message seems to say that it can't serialize my custom class where it should be the dbObject that should be serialized. Here's the exception trace : {noformat} Exception in thread "main" java.lang.RuntimeException: json can't serialize type : class kam.albert.domain.test.post.TestConverterThatFails$MyNested at com.mongodb.util.JSON.serialize(JSON.java:261) at com.mongodb.util.JSON.serialize(JSON.java:210) at com.mongodb.util.JSON.serialize(JSON.java:141) at com.mongodb.util.JSON.serialize(JSON.java:141) at com.mongodb.util.JSON.serialize(JSON.java:58) at com.mongodb.BasicDBObject.toString(BasicDBObject.java:84) at java.lang.String.valueOf(Unknown Source) at java.lang.StringBuilder.append(Unknown Source) at org.springframework.data.mongodb.core.MongoTemplate$12.doInCollection(MongoTemplate.java:840) at org.springframework.data.mongodb.core.MongoTemplate$12.doInCollection(MongoTemplate.java:826) at org.springframework.data.mongodb.core.MongoTemplate.execute(MongoTemplate.java:368) at org.springframework.data.mongodb.core.MongoTemplate.doUpdate(MongoTemplate.java:826) at org.springframework.data.mongodb.core.MongoTemplate.updateFirst(MongoTemplate.java:812) at kam.albert.domain.test.post.TestConverterThatFails.test(TestConverterThatFails.java:50) at kam.albert.domain.test.post.TestConverterThatFails.main(TestConverterThatFails.java:30) {noformat}
    via by albert kam,
  • When enum value is used as part of {{Criteria}} object, when {{Query}} is throwing exception, serialization is failing. Following is stacktrace: {noformat} java.lang.RuntimeException: json can't serialize type : class mypackage.MyClass$UserStatus at com.mongodb.util.ClassMapBasedObjectSerializer.serialize(ClassMapBasedObjectSerializer.java:77) at com.mongodb.util.JSONSerializers$MapSerializer.serialize(JSONSerializers.java:317) at com.mongodb.util.ClassMapBasedObjectSerializer.serialize(ClassMapBasedObjectSerializer.java:79) at com.mongodb.util.JSONSerializers$MapSerializer.serialize(JSONSerializers.java:317) at com.mongodb.util.ClassMapBasedObjectSerializer.serialize(ClassMapBasedObjectSerializer.java:79) at com.mongodb.util.JSON.serialize(JSON.java:55) at com.mongodb.util.JSON.serialize(JSON.java:40) at com.mongodb.BasicDBObject.toString(BasicDBObject.java:83) at java.lang.String.valueOf(String.java:2854) at java.lang.StringBuilder.append(StringBuilder.java:128) at org.springframework.data.mongodb.core.query.Query.addCriteria(Query.java:88) {noformat} Also on side note (may qualify for another bug which caused above exception to appear) : MongoDB allows same multiple criteria on same key, For e.g., db.business.find({status:'Active', status:{$ne:'InActive'}},{status:1}) is working fine from mongodb console. If I try same thing using Criteria it causes exception. I can work around the problem, but in certain cases I would like to allow this where criteria is prepared dynamically.
    via by Poorna Subhash,
  • Incorrectly constructed queries with java.time classes respond with a incorrect error: {code:java} LocalDate firstDayOfYear = LocalDate.ofYearDay(year, 1).with(TemporalAdjusters.firstDayOfYear()); LocalDate lastDayOfYear = LocalDate.ofYearDay(year, 1).with(TemporalAdjusters.lastDayOfYear()); LocalDateTime firstDayOfYearTime = LocalDateTime.of(firstDayOfYear.getYear(), firstDayOfYear.getMonth(), firstDayOfYear.getDayOfMonth(), 0, 0); LocalDateTime lastDayOfYearTime = LocalDateTime.of(lastDayOfYear.getYear(), lastDayOfYear.getMonth(), lastDayOfYear.getDayOfMonth(), 23, 59, 59); Instant firstDayOfYearInstant = firstDayOfYearTime.toInstant(ZoneOffset.UTC); Instant lastDayOfYearInstant = lastDayOfYearTime.toInstant(ZoneOffset.UTC); Query q = query( where("effectiveExpireOptionalDateGroup.effectiveDate").gte(firstDayOfYear) .and("effectiveExpireOptionalDateGroup.effectiveDate").lte(lastDayOfYear) ); Query q = query( where("effectiveExpireOptionalDateGroup.effectiveDate").gte(firstDayOfYearTime) .and("effectiveExpireOptionalDateGroup.effectiveDate").lte(lastDayOfYearTime) ); Query q = query( where("effectiveExpireOptionalDateGroup.effectiveDate").gte(firstDayOfYearInstant) .and("effectiveExpireOptionalDateGroup.effectiveDate").lte(lastDayOfYearInstant) ); {code} {code:java} Exception in thread "main" java.lang.RuntimeException: json can't serialize type : class java.time.LocalDate at com.mongodb.util.ClassMapBasedObjectSerializer.serialize(ClassMapBasedObjectSerializer.java:77) at com.mongodb.util.JSONSerializers$MapSerializer.serialize(JSONSerializers.java:319) at com.mongodb.util.ClassMapBasedObjectSerializer.serialize(ClassMapBasedObjectSerializer.java:79) at com.mongodb.util.JSON.serialize(JSON.java:54) at com.mongodb.util.JSON.serialize(JSON.java:40) at com.mongodb.BasicDBObject.toString(BasicDBObject.java:97) at java.lang.String.valueOf(String.java:2979) at java.lang.StringBuilder.append(StringBuilder.java:131) at org.springframework.data.mongodb.core.query.Criteria.setValue(Criteria.java:679) at org.springframework.data.mongodb.core.query.Criteria.getCriteriaObject(Criteria.java:612) at org.springframework.data.mongodb.core.query.Criteria.elemMatch(Criteria.java:522) {code} If the query is correct, java.time classes parse correctly. {code:java} Query q = new Criteria().andOperator( where("rate.effectiveExpireOptionalDateGroup.effectiveDate").gte(firstDayOfYearTime), where("rate.effectiveExpireOptionalDateGroup.effectiveDate").lte(lastDayOfYearTime)) ); {code}
    via by Bjorn Harvold,
  • When enum value is used as part of {{Criteria}} object, when {{Query}} is throwing exception, serialization is failing. Following is stacktrace: {noformat} java.lang.RuntimeException: json can't serialize type : class mypackage.MyClass$UserStatus at com.mongodb.util.ClassMapBasedObjectSerializer.serialize(ClassMapBasedObjectSerializer.java:77) at com.mongodb.util.JSONSerializers$MapSerializer.serialize(JSONSerializers.java:317) at com.mongodb.util.ClassMapBasedObjectSerializer.serialize(ClassMapBasedObjectSerializer.java:79) at com.mongodb.util.JSONSerializers$MapSerializer.serialize(JSONSerializers.java:317) at com.mongodb.util.ClassMapBasedObjectSerializer.serialize(ClassMapBasedObjectSerializer.java:79) at com.mongodb.util.JSON.serialize(JSON.java:55) at com.mongodb.util.JSON.serialize(JSON.java:40) at com.mongodb.BasicDBObject.toString(BasicDBObject.java:83) at java.lang.String.valueOf(String.java:2854) at java.lang.StringBuilder.append(StringBuilder.java:128) at org.springframework.data.mongodb.core.query.Query.addCriteria(Query.java:88) {noformat} Also on side note (may qualify for another bug which caused above exception to appear) : MongoDB allows same multiple criteria on same key, For e.g., db.business.find({status:'Active', status:{$ne:'InActive'}},{status:1}) is working fine from mongodb console. If I try same thing using Criteria it causes exception. I can work around the problem, but in certain cases I would like to allow this where criteria is prepared dynamically.
    via by Poorna Subhash,
    • java.lang.RuntimeException: json can't serialize type : class kam.albert.domain.test.post.TestConverterThatFails$MyNested at com.mongodb.util.JSON.serialize(JSON.java:261) at com.mongodb.util.JSON.serialize(JSON.java:210) at com.mongodb.util.JSON.serialize(JSON.java:141) at com.mongodb.util.JSON.serialize(JSON.java:141) at com.mongodb.util.JSON.serialize(JSON.java:58) at com.mongodb.BasicDBObject.toString(BasicDBObject.java:84) at java.lang.String.valueOf(Unknown Source) at java.lang.StringBuilder.append(Unknown Source) at org.springframework.data.mongodb.core.MongoTemplate$12.doInCollection(MongoTemplate.java:840) at org.springframework.data.mongodb.core.MongoTemplate$12.doInCollection(MongoTemplate.java:826) at org.springframework.data.mongodb.core.MongoTemplate.execute(MongoTemplate.java:368) at org.springframework.data.mongodb.core.MongoTemplate.doUpdate(MongoTemplate.java:826) at org.springframework.data.mongodb.core.MongoTemplate.updateFirst(MongoTemplate.java:812) at kam.albert.domain.test.post.TestConverterThatFails.test(TestConverterThatFails.java:50) at kam.albert.domain.test.post.TestConverterThatFails.main(TestConverterThatFails.java:30)

    Users with the same issue

    Unknown visitor
    Unknown visitor1 times, last one,
    Unknown visitor
    Unknown visitor1 times, last one,
    Unknown visitor
    Unknown visitor1 times, last one,