public class KMongoConfiguration
Use this class to customize the default behaviour of KMongo jackson bindings.
public static KMongoConfiguration INSTANCE
Use this class to customize the default behaviour of KMongo jackson bindings.
@NotNull public com.fasterxml.jackson.databind.ObjectMapper getExtendedJsonMapper()
Manage mongo extended json format.
public void setExtendedJsonMapper(@NotNull
com.fasterxml.jackson.databind.ObjectMapper p)
Manage mongo extended json format.
@NotNull public com.fasterxml.jackson.databind.ObjectMapper getBsonMapper()
Manage bson format.
public void setBsonMapper(@NotNull
com.fasterxml.jackson.databind.ObjectMapper p)
Manage bson format.
@NotNull public com.fasterxml.jackson.databind.ObjectMapper getBsonMapperCopy()
Basically a copy of bsonMapper without org.litote.kmongo.jackson.KMongoBsonFactory.
Used by org.litote.kmongo.jackson.JacksonCodec to resolves specific serialization issues.
bsonMapperpublic void setBsonMapperCopy(@NotNull
com.fasterxml.jackson.databind.ObjectMapper p)
Basically a copy of bsonMapper without org.litote.kmongo.jackson.KMongoBsonFactory.
Used by org.litote.kmongo.jackson.JacksonCodec to resolves specific serialization issues.
bsonMapperpublic void registerBsonModule(@NotNull
com.fasterxml.jackson.databind.Module module)
Register a jackson Module for the two bson mappers, bsonMapper and bsonMapperCopy.
For example, if you need to manage DBRefs autoloading, you can write this kind of module:
class KMongoBeanDeserializer(deserializer:BeanDeserializer) : ThrowableDeserializer(deserializer) {
override fun deserializeFromObject(jp: JsonParser, ctxt: DeserializationContext): Any? {
if(jp.currentName == "\$ref") {
val ref = jp.nextTextValue()
jp.nextValue()
val id = jp.getValueAsString()
while(jp.currentToken != JsonToken.END_OBJECT) jp.nextToken()
return database.getCollection(ref).withDocumentClass(_beanType.rawClass).findOneById(id)
} else {
return super.deserializeFromObject(jp, ctxt)
}
}
}
class KMongoBeanDeserializerModifier : BeanDeserializerModifier() {
override fun modifyDeserializer(config: DeserializationConfig, beanDesc: BeanDescription, deserializer: JsonDeserializer<*>): JsonDeserializer<*> {
return if(deserializer is BeanDeserializer) {
KMongoBeanDeserializer( deserializer)
} else {
deserializer
}
}
}
KMongoConfiguration.registerBsonModule(SimpleModule().setDeserializerModifier(KMongoBeanDeserializerModifier()))bsonMapper,
bsonMapperCopy,
DBRefspublic void resetConfiguration()
Reset the jackson configuration.
Useful if you need to manage hot class reloading (see https://github.com/Litote/kmongo/issues/75 )
Usage:
KMongoConfiguration.registerBsonModule(MyModule()) client = KMongo.createClient(..)
// then reloading KMongoConfiguration.resetConfiguration() KMongoConfiguration.registerBsonModule(MyModule()) client = KMongo.createClient(..)