GH-188 Ensured default ObjectMapper is created (AWS)
Ensured that the default instance of ObjectMapper is created in the event ObjectMapper configuration is missing (i.e., JacksonAutoConfiguration) in AWS adapter Resolves #188
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2017 the original author or authors.
|
* Copyright 2017-1018 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -28,18 +28,18 @@ import com.amazonaws.services.lambda.runtime.RequestStreamHandler;
|
|||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
|
||||||
import org.reactivestreams.Publisher;
|
import org.reactivestreams.Publisher;
|
||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
|
||||||
import reactor.core.publisher.Flux;
|
import reactor.core.publisher.Flux;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Dave Syer
|
* @author Dave Syer
|
||||||
|
* @author Oleg Zhurakousky
|
||||||
*/
|
*/
|
||||||
public class SpringBootStreamHandler extends SpringFunctionInitializer
|
public class SpringBootStreamHandler extends SpringFunctionInitializer
|
||||||
implements RequestStreamHandler {
|
implements RequestStreamHandler {
|
||||||
|
|
||||||
@Autowired
|
@Autowired(required=false)
|
||||||
private ObjectMapper mapper;
|
private ObjectMapper mapper;
|
||||||
|
|
||||||
public SpringBootStreamHandler() {
|
public SpringBootStreamHandler() {
|
||||||
@@ -50,6 +50,14 @@ public class SpringBootStreamHandler extends SpringFunctionInitializer
|
|||||||
super(configurationClass);
|
super(configurationClass);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void initialize() {
|
||||||
|
super.initialize();
|
||||||
|
if (this.mapper == null) {
|
||||||
|
this.mapper = new ObjectMapper();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handleRequest(InputStream input, OutputStream output, Context context)
|
public void handleRequest(InputStream input, OutputStream output, Context context)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2016-2017 the original author or authors.
|
* Copyright 2016-2018 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -32,15 +32,25 @@ import static org.assertj.core.api.Assertions.assertThat;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Dave Syer
|
* @author Dave Syer
|
||||||
*
|
* @author Oleg Zhurakousky
|
||||||
*/
|
*/
|
||||||
public class SpringBootStreamHandlerTests {
|
public class SpringBootStreamHandlerTests {
|
||||||
|
|
||||||
private SpringBootStreamHandler handler;
|
private SpringBootStreamHandler handler;
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void functionBean() throws Exception {
|
public void functionBeanWithJacksonConfig() throws Exception {
|
||||||
handler = new SpringBootStreamHandler(FunctionConfig.class);
|
handler = new SpringBootStreamHandler(FunctionConfigWithJackson.class);
|
||||||
|
handler.initialize();
|
||||||
|
ByteArrayOutputStream output = new ByteArrayOutputStream();
|
||||||
|
handler.handleRequest(new ByteArrayInputStream("{\"value\":\"foo\"}".getBytes()),
|
||||||
|
output, null);
|
||||||
|
assertThat(output.toString()).isEqualTo("{\"value\":\"FOO\"}");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void functionBeanWithoutJacksonConfig() throws Exception {
|
||||||
|
handler = new SpringBootStreamHandler(FunctionConfigWithoutJackson.class);
|
||||||
handler.initialize();
|
handler.initialize();
|
||||||
ByteArrayOutputStream output = new ByteArrayOutputStream();
|
ByteArrayOutputStream output = new ByteArrayOutputStream();
|
||||||
handler.handleRequest(new ByteArrayInputStream("{\"value\":\"foo\"}".getBytes()),
|
handler.handleRequest(new ByteArrayInputStream("{\"value\":\"foo\"}".getBytes()),
|
||||||
@@ -51,7 +61,16 @@ public class SpringBootStreamHandlerTests {
|
|||||||
@Configuration
|
@Configuration
|
||||||
@Import({ ContextFunctionCatalogAutoConfiguration.class,
|
@Import({ ContextFunctionCatalogAutoConfiguration.class,
|
||||||
JacksonAutoConfiguration.class })
|
JacksonAutoConfiguration.class })
|
||||||
protected static class FunctionConfig {
|
protected static class FunctionConfigWithJackson {
|
||||||
|
@Bean
|
||||||
|
public Function<Foo, Bar> function() {
|
||||||
|
return foo -> new Bar(foo.getValue().toUpperCase());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
@Import({ ContextFunctionCatalogAutoConfiguration.class})
|
||||||
|
protected static class FunctionConfigWithoutJackson {
|
||||||
@Bean
|
@Bean
|
||||||
public Function<Foo, Bar> function() {
|
public Function<Foo, Bar> function() {
|
||||||
return foo -> new Bar(foo.getValue().toUpperCase());
|
return foo -> new Bar(foo.getValue().toUpperCase());
|
||||||
|
|||||||
Reference in New Issue
Block a user