Skip to content
This repository was archived by the owner on Feb 23, 2023. It is now read-only.

Commit 882297a

Browse files
committed
Modified funuction to use POJO as input
- created Person POJO in a different package - modified function to use such pojo - added TypeHint to the main - updated docs
1 parent 384d8ca commit 882297a

File tree

5 files changed

+41
-15
lines changed

5 files changed

+41
-15
lines changed

samples/cloud-function-aws/README.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,11 @@ $> ./build.sh
2626
2727
```
2828

29+
>>NOTE: You will notice we apply `@TypeHint(types = {Person.class}` (see `DemoApplication`). Given that JSON converter will apply reflection to serialize/de-serialize `Person` type for the function input we need to provide minimal reflection configuration and `@TypeHint` will let us do just that.
30+
2931
### Deploy and test
3032

3133
- Navigate to AWS Lambda dashboard and create a new function (name it anyway you want).
3234
- In "Runtime" go to `Custom Runtime` and select one of the options available.
3335
- Upload generated `cloud-function-aws-0.0.1-SNAPSHOT-native-zip.zip`.
34-
- Finally test by providing JSON-style string value via 'Test' tab. For example `"John"`. The output should be `"Hi John!"`
36+
- Finally test by providing JSON-style string value via 'Test' tab. For example `"John"`. The output should be `"Hi JOHN!"`

samples/cloud-function-aws/src/main/java/com/example/demo/DemoApplication.java

+4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@
22

33
import org.springframework.boot.SpringApplication;
44
import org.springframework.boot.autoconfigure.SpringBootApplication;
5+
import org.springframework.nativex.hint.TypeHint;
56

7+
import com.example.demo.domain.Person;
8+
9+
@TypeHint(types = {Person.class})
610
@SpringBootApplication
711
public class DemoApplication {
812

samples/cloud-function-aws/src/main/java/com/example/demo/Foobar.java

-14
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package com.example.demo;
2+
3+
import java.util.function.Function;
4+
5+
import org.springframework.stereotype.Component;
6+
7+
import com.example.demo.domain.Person;
8+
9+
@Component
10+
public class NameUppercaser implements Function<Person, String> {
11+
12+
@Override
13+
public String apply(Person input) {
14+
return "hi " + input.getName().toUpperCase() + "!";
15+
}
16+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package com.example.demo.domain;
2+
3+
public class Person {
4+
private String name;
5+
6+
public String getName() {
7+
return name;
8+
}
9+
10+
public void setName(String name) {
11+
this.name = name;
12+
}
13+
14+
@Override
15+
public String toString() {
16+
return name;
17+
}
18+
}

0 commit comments

Comments
 (0)