r/javahelp • u/ebykka • May 23 '22
Micronaut returns the empty body
Hi,
In my "Hello World" 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.
{
"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.
Is there any other way to serialize the map?