@Bean @ConditionalOnClass(CamelContext.class) @ConditionalOnMissingBean(GsonDataFormat.class) public GsonDataFormat configureGsonDataFormat(CamelContext camelContext, GsonDataFormatConfiguration configuration) throws Exception { GsonDataFormat dataformat = new GsonDataFormat(); if (dataformat instanceof CamelContextAware) { ((CamelContextAware) dataformat).setCamelContext(camelContext); } Map<String, Object> parameters = new HashMap<>(); IntrospectionSupport.getProperties(configuration, parameters, null, false); IntrospectionSupport.setProperties(camelContext, camelContext.getTypeConverter(), dataformat, parameters); return dataformat; }
@Override public void configure() throws Exception { DataFormat json = new GsonDataFormat(Projeto.class); from("activemq:queue:projetos") .id("activemq-route") .log("Recebendo mensagem da fila 'projetos': ${in.body}") .choice() .when(body().isInstanceOf(String.class)) .unmarshal(json) .bean(this.processor, "processaPojo") .when(body().isInstanceOf(Map.class)) .bean(this.processor, "processaMap") .otherwise() .bean(this.processor, "processaTexto"); }
@Override public ImmutableMap<String, Object> beans() { return ImmutableMap.of("json-gson", new GsonDataFormat()); }