Announcement Announcement Module
Collapse
No announcement yet.
Converter not working when having multiple criterias in query Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Converter not working when having multiple criterias in query

    Using spring mongo 1.1.0 release version, and mongo-java-driver 2.9.1 here.

    So, in short, i have an custom class IdKey that should convert to ObjectId, having registered the converter reader and writer in my xml file.

    And, the write conversion works great. The read conversion works great in ops.findById(). But for criterias, the conversion is having some problems.

    So, this query criteria works fine (i am using ops.findByOne(query)):
    Code:
    query.addCriteria(
    	Criteria.where("_id").in(Lists.<IdKey>newArrayList(cupcake.getId()))
    );
    and this one is working well as well :
    Code:
    query.addCriteria(
    	new Criteria()
    		.orOperator(
    			Criteria.where("_id").in(Lists.<IdKey>newArrayList(cupcake.getId())
    		)
    	)
    );
    But these all below suffer from this exception : json can't serialize type : class kam.albert.domain.IdKey :
    Code:
    query.addCriteria(
    	new Criteria()
    		.orOperator(
    			Criteria.where("_id").in(Lists.<IdKey>newArrayList(cupcake.getId())
    		)
    		.and("_id").in(Lists.<IdKey>newArrayList(cupcake.getId()))
    	)
    );
    Code:
    query.addCriteria(
    	new Criteria()
    		.andOperator(
    			Criteria.where("_id").in(Lists.<IdKey>newArrayList(cupcake.getId())
    		)
    		.and("_id").in(Lists.<IdKey>newArrayList(cupcake.getId()))
    	)
    );
    Code:
    query.addCriteria(
    	Criteria.where("_id").in(Lists.<IdKey>newArrayList(cupcake.getId()))
    	.and("_id").in(Lists.<IdKey>newArrayList(cupcake.getId()))
    );
    Code:
    query.addCriteria(
    	Criteria.where("_id").in(Lists.<IdKey>newArrayList(cupcake.getId()))
    	.and("_id").in(Lists.<IdKey>newArrayList(cupcake.getId()))
    );
    Code:
    query.addCriteria(
    	Criteria.where("_id").in(Lists.<IdKey>newArrayList(cupcake.getId()))
    );
    query.addCriteria(
    	Criteria.where("_id").in(Lists.<IdKey>newArrayList(cupcake.getId()))
    );
    The complete exception trace is :
    Code:
    Exception in thread "main" java.lang.RuntimeException: json can't serialize type : class kam.albert.domain.IdKey
    	at com.mongodb.util.ClassMapBasedObjectSerializer.serialize(ClassMapBasedObjectSerializer.java:77)
    	at com.mongodb.util.JSONSerializers$IterableSerializer.serialize(JSONSerializers.java:280)
    	at com.mongodb.util.ClassMapBasedObjectSerializer.serialize(ClassMapBasedObjectSerializer.java:79)
    	at com.mongodb.util.JSONSerializers$MapSerializer.serialize(JSONSerializers.java:307)
    	at com.mongodb.util.ClassMapBasedObjectSerializer.serialize(ClassMapBasedObjectSerializer.java:79)
    	at com.mongodb.util.JSON.serialize(JSON.java:56)
    	at com.mongodb.util.JSON.serialize(JSON.java:41)
    	at com.mongodb.BasicDBObject.toString(BasicDBObject.java:83)
    	at java.lang.String.valueOf(Unknown Source)
    	at java.lang.StringBuilder.append(Unknown Source)
    	at org.springframework.data.mongodb.core.query.Criteria.setValue(Criteria.java:494)
    	at org.springframework.data.mongodb.core.query.Criteria.getCriteriaObject(Criteria.java:446)
    	at org.springframework.data.mongodb.core.query.Criteria.createCriteriaList(Criteria.java:484)
    	at org.springframework.data.mongodb.core.query.Criteria.orOperator(Criteria.java:403)
    	at kam.albert.lab.convert.TestObjectId.testUuid(TestObjectId.java:62)
    	at kam.albert.lab.convert.TestObjectId.main(TestObjectId.java:34)

    Even a stranger error occurs when doing this :
    Code:
    query.addCriteria(
    	new Criteria()
    		.orOperator(
    			Criteria.where("_id").in(Lists.<IdKey>newArrayList(cupcake.getId()),
    			Criteria.where("_id").in(Lists.<IdKey>newArrayList(cupcake.getId())
    		)
    	)
    ));
    And this will result in stackoverflow error instead :
    Code:
    Exception in thread "main" java.lang.StackOverflowError
    	at java.util.HashMap$KeyIterator.<init>(Unknown Source)
    	at java.util.HashMap$KeyIterator.<init>(Unknown Source)
    	at java.util.HashMap.newKeyIterator(Unknown Source)
    	at java.util.HashMap$KeySet.iterator(Unknown Source)
    	at java.util.HashSet.iterator(Unknown Source)
    	at org.springframework.data.mongodb.core.convert.CustomConversions.getCustomTarget(CustomConversions.java:288)
    	at org.springframework.data.mongodb.core.convert.CustomConversions.getCustomWriteTarget(CustomConversions.java:235)
    	at org.springframework.data.mongodb.core.convert.MappingMongoConverter.writeInternal(MappingMongoConverter.java:315)
    	at org.springframework.data.mongodb.core.convert.MappingMongoConverter.writeCollectionInternal(MappingMongoConverter.java:514)
    	at org.springframework.data.mongodb.core.convert.MappingMongoConverter.createCollection(MappingMongoConverter.java:474)
    	at org.springframework.data.mongodb.core.convert.MappingMongoConverter.writePropertyInternal(MappingMongoConverter.java:405)
    	at org.springframework.data.mongodb.core.convert.MappingMongoConverter$3.doWithPersistentProperty(MappingMongoConverter.java:373)
    	at org.springframework.data.mongodb.core.convert.MappingMongoConverter$3.doWithPersistentProperty(MappingMongoConverter.java:362)
    	at org.springframework.data.mapping.model.BasicPersistentEntity.doWithProperties(BasicPersistentEntity.java:195)
    	at org.springframework.data.mongodb.core.convert.MappingMongoConverter.writeInternal(MappingMongoConverter.java:362)
    	at org.springframework.data.mongodb.core.convert.MappingMongoConverter.writeInternal(MappingMongoConverter.java:334)
    	at org.springframework.data.mongodb.core.convert.MappingMongoConverter.writeCollectionInternal(MappingMongoConverter.java:514)
    	at org.springframework.data.mongodb.core.convert.MappingMongoConverter.createCollection(MappingMongoConverter.java:474)
    	at org.springframework.data.mongodb.core.convert.MappingMongoConverter.writePropertyInternal(MappingMongoConverter.java:405)
    	at org.springframework.data.mongodb.core.convert.MappingMongoConverter$3.doWithPersistentProperty(MappingMongoConverter.java:373)
    	at org.springframework.data.mongodb.core.convert.MappingMongoConverter$3.doWithPersistentProperty(MappingMongoConverter.java:362)
    	at org.springframework.data.mapping.model.BasicPersistentEntity.doWithProperties(BasicPersistentEntity.java:195)
    	at org.springframework.data.mongodb.core.convert.MappingMongoConverter.writeInternal(MappingMongoConverter.java:362)
    	at org.springframework.data.mongodb.core.convert.MappingMongoConverter.writeInternal(MappingMongoConverter.java:334)
    	at org.springframework.data.mongodb.core.convert.MappingMongoConverter.writeCollectionInternal(MappingMongoConverter.java:514)
    	at org.springframework.data.mongodb.core.convert.MappingMongoConverter.createCollection(MappingMongoConverter.java:474)
    	at org.springframework.data.mongodb.core.convert.MappingMongoConverter.writePropertyInternal(MappingMongoConverter.java:405)
    	at org.springframework.data.mongodb.core.convert.MappingMongoConverter$3.doWithPersistentProperty(MappingMongoConverter.java:373)
    	at org.springframework.data.mongodb.core.convert.MappingMongoConverter$3.doWithPersistentProperty(MappingMongoConverter.java:362)
    And just to make sure, every errors that happened before are gone if i convert from IdKey collection to ObjectId collection manually.

    Any ideas on what is happenning, and whether this is a bug ?

    Thank you !
    Last edited by albert_kam; Jan 6th, 2013, 01:57 AM.
Working...
X