63.4. Jackson を使用した自動型変換
camel-jackson モジュールを使用すると、Jackson を Type Converter として統合できます。これは、Camel の型コンバーターと統合するJAXB と同様の方法で機能します。
この camel-jackson を使用するには、次のように CamelContext グローバルオプションで次のオプションを設定することによって有効にする必要があります。
@Bean
CamelContextConfiguration contextConfiguration() {
return new CamelContextConfiguration() {
@Override
public void beforeApplicationStart(CamelContext context) {
// Enable Jackson JSON type converter.
context.getGlobalOptions().put(JacksonConstants.ENABLE_TYPE_CONVERTER, "true");
// Allow Jackson JSON to convert to pojo types also
// (by default Jackson only converts to String and other simple types)
getContext().getGlobalOptions().put(JacksonConstants.TYPE_CONVERTER_TO_POJO, "true");
}
@Override
public void afterApplicationStart(CamelContext camelContext) {
}
};
}
camel-jackson 型コンバーターは JAXB と統合されるため、Jackson が使用できる JAXB アノテーションで POJO クラスにアノテーションを付加できます。POJO クラスで Jackson 独自のアノテーションを使用することもできます。