java.lang.RuntimeException: json can't serialize type : class kam.albert.domain.test.post.TestConverterThatFails$MyNested

Spring JIRA | albert kam | 5 years ago
  1. 0

    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}

    Spring JIRA | 5 years ago | albert kam
    java.lang.RuntimeException: json can't serialize type : class kam.albert.domain.test.post.TestConverterThatFails$MyNested
  2. 0

    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}

    Spring JIRA | 5 years ago | albert kam
    java.lang.RuntimeException: json can't serialize type : class kam.albert.domain.test.post.TestConverterThatFails$MyNested
  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 | 12 months 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 | 12 months 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 kam.albert.domain.test.post.TestConverterThatFails$MyNested

      at com.mongodb.util.JSON.serialize()
    2. MongoDB Java Driver
      BasicDBObject.toString
      1. com.mongodb.util.JSON.serialize(JSON.java:261)
      2. com.mongodb.util.JSON.serialize(JSON.java:210)
      3. com.mongodb.util.JSON.serialize(JSON.java:141)
      4. com.mongodb.util.JSON.serialize(JSON.java:141)
      5. com.mongodb.util.JSON.serialize(JSON.java:58)
      6. com.mongodb.BasicDBObject.toString(BasicDBObject.java:84)
      6 frames
    3. Java RT
      StringBuilder.append
      1. java.lang.String.valueOf(Unknown Source)
      2. java.lang.StringBuilder.append(Unknown Source)
      2 frames
    4. Spring Data MongoDB - Core
      MongoTemplate.updateFirst
      1. org.springframework.data.mongodb.core.MongoTemplate$12.doInCollection(MongoTemplate.java:840)
      2. org.springframework.data.mongodb.core.MongoTemplate$12.doInCollection(MongoTemplate.java:826)
      3. org.springframework.data.mongodb.core.MongoTemplate.execute(MongoTemplate.java:368)
      4. org.springframework.data.mongodb.core.MongoTemplate.doUpdate(MongoTemplate.java:826)
      5. org.springframework.data.mongodb.core.MongoTemplate.updateFirst(MongoTemplate.java:812)
      5 frames
    5. kam.albert.domain
      TestConverterThatFails.main
      1. kam.albert.domain.test.post.TestConverterThatFails.test(TestConverterThatFails.java:50)
      2. kam.albert.domain.test.post.TestConverterThatFails.main(TestConverterThatFails.java:30)
      2 frames