I'm using spring-data-mongodb-1.2.0.RELEASE. I have two classes A and B where B has a reference to A and it is annotated with @DBRef.
Class A:
Class B:
After creating and associating A and B instances:
I'm able to execute the next query:
But(!!!), when I'm executing findAndRemove:
I'm getting this:
java.lang.RuntimeException: json can't serialize type : class org.jasig.cas.ticket.registry.entities.A at com.mongodb.util.ClassMapBasedObjectSerializer.ser ialize(ClassMapBasedObjectSerializer.java:77) at com.mongodb.util.JSONSerializers$MapSerializer.ser ialize(JSONSerializers.java:307) at com.mongodb.util.ClassMapBasedObjectSerializer.ser ialize(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.j ava:83) at java.lang.String.valueOf(String.java:2826) at java.lang.StringBuilder.append(StringBuilder.java: 115) at org.springframework.data.mongodb.core.MongoTemplat e.doFindAndRemove(MongoTemplate.java:1392) at org.springframework.data.mongodb.core.MongoTemplat e.findAndRemove(MongoTemplate.java:572) at org.springframework.data.mongodb.core.MongoTemplat e.findAndRemove(MongoTemplate.java:568)
Does someone have an idea why?
Class A:
Code:
@Document(collection = "a")
public class A {
@Id
public String id;
/** The TicketGrantingTicket this is associated with. */
@Field
public String name;
public A(String id, String name) {
this.id = id;
this.name = name;
}
}
Code:
@Document(collection = "b")
public class B {
@Id
public String id;
@Field
public String name;
@DBRef
@Indexed
public A a;
public B(String id, String name, A a) {
super();
this.id = id;
this.name = name;
this.a = a;
}
}
Code:
A a1 = new A("a-2", "a-2");
mongoOperations.insert(a1);
B b1 = new B("b-2", "b-2", a1);
mongoOperations.insert(b1);
Code:
B fromDB = mongoOperations.findOne(Query.query(Criteria.where("a").is(a1)), B.class);
Code:
fromDB = mongoOperations.findAndRemove(Query.query(Criteria.where("a").is(a1)), B.class);
java.lang.RuntimeException: json can't serialize type : class org.jasig.cas.ticket.registry.entities.A at com.mongodb.util.ClassMapBasedObjectSerializer.ser ialize(ClassMapBasedObjectSerializer.java:77) at com.mongodb.util.JSONSerializers$MapSerializer.ser ialize(JSONSerializers.java:307) at com.mongodb.util.ClassMapBasedObjectSerializer.ser ialize(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.j ava:83) at java.lang.String.valueOf(String.java:2826) at java.lang.StringBuilder.append(StringBuilder.java: 115) at org.springframework.data.mongodb.core.MongoTemplat e.doFindAndRemove(MongoTemplate.java:1392) at org.springframework.data.mongodb.core.MongoTemplat e.findAndRemove(MongoTemplate.java:572) at org.springframework.data.mongodb.core.MongoTemplat e.findAndRemove(MongoTemplate.java:568)
Does someone have an idea why?