Spring data MongoDb: MappingMongoConverter remove _class
The default MappingMongoConverter adds a custom type key ("_class") to each object in the database. So, if I create a Person:
Code:
package my.dto;
public class Person {
String name;
public Person(String name) {
this.name = name;
}
}
and save it to the db:
Code:
MongoOperations ops = new MongoTemplate(new Mongo(), "users");
ops.insert(new Person("Joe"));
the resulting object in the mongo will be:
Code:
{ "_id" : ObjectId("4e2ca049744e664eba9d1e11"), "_class" : "my.dto.Person", "name" : "Joe" }
Questions:
1. What are the implications of moving the Person class into a different namespace?
2. Is it possible not to pollute the object with the "_class" key; without writing a unique converter just for the Person class?
Also posted on StackOverflow.
Did you ever find a workaround for this?
So what is the story with this? Is there no way to prevent the "_class" field from getting stored in MongoDB?
Thanks so much for your reply.
I will give your suggestions a try!