Reputation: 5686
I have looked at the documentation but couldn't find how to add custom type converters for mongoDB. How can one do it ?
Upvotes: 0
Views: 671
Reputation: 7998
First of all I think that fromAnyObjectToDBObject
default converter can resolve most of your cases. It uses Jackson library and all you need is to mark your custom classes with right annotations.
Anyway, if you still need custom converter, following steps should be performed:
White your conversion logic and mark your class and converter methods with org.apache.camel.Converter
annotation:
package com.acme.converters;
@Converter
public class CustomConverter {
@Converter
public static DBObject fromCustomToDBObject(CustomType object) {
// conversion logic
}
}
Create following resource file to be placed in your result jar:
META-INF/services/org/apache/camel/TypeConverter
And list your converter classes in this file:
com.acme.converters.CustomConverter
This file will help Camel to auto-discover your own converters.
You can also take a look at:
META-INF/services/org/apache/camel/TypeConverter
in camel-mongodb-x.x.x.jar to see how default converter definedorg.apache.camel.impl.converter.AnnotationTypeConverterLoader
class to check converters loading logic Upvotes: 2