java.lang.RuntimeException: json can't serialize type : class java.time.LocalDate

Spring JIRA | Bjorn Harvold | 10 months ago
tip
Your exception is missing from the Samebug knowledge base.
Here are the best solutions we found on the Internet.
Click on the to mark the helpful solution and get rewards for you help.
  1. 0

    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}

    Spring JIRA | 10 months ago | Bjorn Harvold
    java.lang.RuntimeException: json can't serialize type : class java.time.LocalDate
  2. 0

    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}

    Spring JIRA | 10 months ago | Bjorn Harvold
    java.lang.RuntimeException: json can't serialize type : class java.time.LocalDate
  3. 0

    com.mongodb.util.JSON.serialize does not support UUID [moved]

    GitHub | 4 years ago | jyemin
    java.lang.RuntimeException: json can't serialize type : class java.util.UUID
  4. Speed up your debug routine!

    Automated exception search integrated into your IDE

  5. 0

    Converter not working when having multiple criterias in query - Tech Forum Network

    techforumnetwork.com | 1 year ago
    java.lang.RuntimeException: json can't serialize type : class kam.albert.domain.IdKey
  6. 0

    Trouble using Jackson 2 with Spring 3.2 - Spring Forum

    spring.io | 1 year ago
    java.lang.RuntimeException: json can't serialize type : class origami.qengine.Channels$Channel

    3 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.RuntimeException

      json can't serialize type : class java.time.LocalDate

      at com.mongodb.util.ClassMapBasedObjectSerializer.serialize()
    2. MongoDB Java Driver
      BasicDBObject.toString
      1. com.mongodb.util.ClassMapBasedObjectSerializer.serialize(ClassMapBasedObjectSerializer.java:77)
      2. com.mongodb.util.JSONSerializers$MapSerializer.serialize(JSONSerializers.java:319)
      3. com.mongodb.util.ClassMapBasedObjectSerializer.serialize(ClassMapBasedObjectSerializer.java:79)
      4. com.mongodb.util.JSON.serialize(JSON.java:54)
      5. com.mongodb.util.JSON.serialize(JSON.java:40)
      6. com.mongodb.BasicDBObject.toString(BasicDBObject.java:97)
      6 frames
    3. Java RT
      StringBuilder.append
      1. java.lang.String.valueOf(String.java:2979)
      2. java.lang.StringBuilder.append(StringBuilder.java:131)
      2 frames
    4. Spring Data MongoDB - Core
      Criteria.elemMatch
      1. org.springframework.data.mongodb.core.query.Criteria.setValue(Criteria.java:679)
      2. org.springframework.data.mongodb.core.query.Criteria.getCriteriaObject(Criteria.java:612)
      3. org.springframework.data.mongodb.core.query.Criteria.elemMatch(Criteria.java:522)
      3 frames