微女归还空体
在我的“ Hello World”本地人(Graalvm)AWS Lambda应用程序中,Micronaut返回空体,而不是将地图序列化为JSON。这是行
@Controller
public class BookController {
private static final DynamoDbClient ddb = DynamoDbClient.builder()
.httpClient(UrlConnectionHttpClient.builder().build()).build();
@Get("/{id}")
public Map<String, AttributeValue> getById(@PathVariable String id) {
GetItemResponse result = ddb.getItem(GetItemRequest.builder()
.tableName("DemoTable")
.key(Map.of(
"id", AttributeValue.builder().s(id).build()))
.build());
System.out.println(result.item());
return result.item();
}
}
system.out.println(result.item())打印所有数据的代码,但是HTTP响应不包含该数据。
这是响应:
{
"statusCode": 200,
"multiValueHeaders": {
"Content-Type": [
"application/json"
],
"Date": [
"Mon, 23 May 2022 20:26:13 GMT"
]
},
"body": "{}",
"isBase64Encoded": false
}
在所有示例中,我看到豆类使用注释 @intropsected 进行适当的JSON序列化,但映射绝对没有。
我试图扩展一个hashmap课程来添加注释,但是没有结果,
@Introspected
public class Asset extends HashMap<String, AttributeValue> {
public Asset() {}
public Asset(Map<String, AttributeValue> map) {
super(map);
}
}
有人可以将我指向我做错了什么?
ps i使用下一个教程,刚刚添加了DynamoDB支持: https://guides.micronaut.io/latest/mn-application-aws-lambda-graalvm-gradle-gradle-java.html
In my "Hello World" native(GraalVM) AWS Lambda application Micronaut returns the empty body instead of serializing a map as JSON. Here is the code
@Controller
public class BookController {
private static final DynamoDbClient ddb = DynamoDbClient.builder()
.httpClient(UrlConnectionHttpClient.builder().build()).build();
@Get("/{id}")
public Map<String, AttributeValue> getById(@PathVariable String id) {
GetItemResponse result = ddb.getItem(GetItemRequest.builder()
.tableName("DemoTable")
.key(Map.of(
"id", AttributeValue.builder().s(id).build()))
.build());
System.out.println(result.item());
return result.item();
}
}
The line System.out.println(result.item()) prints all data but http response does not contain that.
Here is the response:
{
"statusCode": 200,
"multiValueHeaders": {
"Content-Type": [
"application/json"
],
"Date": [
"Mon, 23 May 2022 20:26:13 GMT"
]
},
"body": "{}",
"isBase64Encoded": false
}
In all examples that I have seen beans use annotation @Introspected for proper JSON serialization but Map definitely does not have it.
I tried to extend a HashMap class for adding the annotation, but without the result
@Introspected
public class Asset extends HashMap<String, AttributeValue> {
public Asset() {}
public Asset(Map<String, AttributeValue> map) {
super(map);
}
}
Can someone point me to what I'm doing wrong?
P.S. I use the next tutorial, just added DynamoDB support: https://guides.micronaut.io/latest/mn-application-aws-lambda-graalvm-gradle-java.html
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我能够通过使用 cutomialiserizer 。
I was able to get a response body by using a custom serializer.