Welcome to the new Spring.io forums!
If this is your first visit, be sure to check out the
by clicking the link above, and for security reasons, use the
forgot password link to reset your password..
You may have to register before you can post: click the register
link above to proceed. To start viewing messages, select the forum that you want to visit
from the selection below.
No announcement yet.
Is it possible that "_class" not created in a document?Page Title Module
It is. You can simply configure a DefaultTypeMapper on MappingMongoConverter and setting the typeKey property on the Mapper to null. However, we recommend to let the converter write that information as you pretty much drop the possibility to correctly persist and retrieve subtypes, or working with interfaces inside the domain model.
<bean id="mongoTemplate" class="org.springframework.data.mongodb.core.Mongo Template">
<constructor-arg name="mongoDbFactory" ref="mongoDbFactory" />
<constructor-arg name="mongoConverter" ref="defaultMongoConverter" />
<property name="writeResultChecking" value="EXCEPTION" />
However, I noticed that still this results in creation of an entry in document with key ( which used to be "_class") equals to null, a value with class name ( come.xx.yy.ClassName) and type of String. Also, I noticed with configuring the default type mapper, I could not use my custom convertors any more.
As per your recommendation, we do not have any problem to keep this filed in our database, however; when we send our documents to another system for processing, the "_class" has no usage on the other system. The complain that I have got is that why we are sending this filed when the other system is using different domain and mechanism to DE-serialize documents.
I think the other solution is to write custom convertor for each domain, but that does not make sense.
Unless otherwise there is not other way, I think I should be able to convince our partner, that we integrate with their system, just disregard this field.
Which SD Mongo version are you using? We actually have quite a few test verifying the key not being set if it is null. Beyond that configuring the TypeMapper shouldn't influence the way custom Converters are handled.
We generally consider the type information stored as hint which type to use. So you should be able to configure a ConfigurableTypeMapper which takes a Map of type to alias to create entries like _class = 'B' and then have B resolved against a particular Java type so that the client written in another language could pretty much do the same.
In case you still face issues I fear I need a bit more details.