Example usage for org.springframework.integration.support.json Jackson2JsonObjectMapper Jackson2JsonObjectMapper

List of usage examples for org.springframework.integration.support.json Jackson2JsonObjectMapper Jackson2JsonObjectMapper

Introduction

In this page you can find the example usage for org.springframework.integration.support.json Jackson2JsonObjectMapper Jackson2JsonObjectMapper.

Prototype

public Jackson2JsonObjectMapper(ObjectMapper objectMapper) 

Source Link

Usage

From source file:org.springframework.cloud.consul.bus.ConsulBusAutoConfiguration.java

@Bean
public IntegrationFlow cloudBusConsulInboundFlow() {
    return IntegrationFlows.from(consulInboundChannelAdapter())
            .transform(Transformers.fromJson(RemoteApplicationEvent.class,
                    new Jackson2JsonObjectMapper(objectMapper)))
            .channel(cloudBusInboundChannel) // now set in consulInboundChannelAdapter
            // bean
            .get();/*from w w w . j  av a  2 s .com*/
}

From source file:org.springframework.cloud.consul.bus.ConsulBusIT.java

@Test
public void test003JsonToObject() {
    ObjectMapper objectMapper = new ObjectMapper();
    objectMapper.registerModule(new SubtypeModule(SimpleRemoteEvent.class));
    JsonToObjectTransformer transformer = Transformers.fromJson(RemoteApplicationEvent.class,
            new Jackson2JsonObjectMapper(objectMapper));
    /*/*from  w w w . jav a2  s  .  com*/
     * HashMap<String, Object> map = new HashMap<>(); map.put(JsonHeaders.TYPE_ID,
     * RemoteApplicationEvent.class);
     */
    Message<?> message = transformer.transform(new GenericMessage<>(JSON_PAYLOAD));
    Object payload = message.getPayload();
    assertTrue("payload is of wrong type", payload instanceof RemoteApplicationEvent);
    assertTrue("payload is of wrong type", payload instanceof SimpleRemoteEvent);
    SimpleRemoteEvent event = (SimpleRemoteEvent) payload;
    assertEquals("payload is wrong", "testMessage", event.getMessage());
}