gpt4 book ai didi

java - 急流。如何在不渲染的情况下从 lambda 返回响应?

转载 作者:可可西里 更新时间:2023-11-01 17:05:36 27 4
gpt4 key购买 nike

我需要从 lambda 返回响应而无需额外渲染。我试着这样做:

On.post("/locations/{id:\\d+}").serve((Integer id, Req req, Resp resp) -> {
if (!storageService.locationIsPresent(id)) {
return resp.code(404).json("Location not found!");
}
try {
String request = new String(req.body());
Location location = mapper.readValue(request, Location.class);
storageService.updateLocation(id, location.getCountry(), location.getCity(), location.getPlace(), location.getDistance() );
} catch (Exception ex) {
return resp.code(400).json("Bad request!");
}
return resp.code(200).body(EMPTY_RESP);
});

但结果我得到了一个异常(exception):

ERROR | 20/Aug/2017 14:19:53:460 | executor2 | org.rapidoid.http.impl.lowlevel.LowLevelHttpIO | Error occurred when handling request! | error = java.lang.RuntimeException: com.fasterxml.jackson.databind.JsonMappingException: No serializer found for class org.rapidoid.http.impl.RespImpl and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationFeature.FAIL_ON_EMPTY_BEANS) java.lang.RuntimeException: com.fasterxml.jackson.databind.JsonMappingException: No serializer found for class org.rapidoid.http.impl.RespImpl and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationFeature.FAIL_ON_EMPTY_BEANS)

请告诉我如何正确操作。

而且我还想知道如何配置服务器以更快地响应每秒大量请求。因为在我的情况下它非常慢。

提前致谢!

最佳答案

尝试像下面这样配置你的映射器, ObjectMapper 映射器 = new ObjectMapper();
mapper.setVisibility(PropertyAccessor.FIELD, Visibility.ANY);
这是有关该问题的一些信息, http://www.baeldung.com/jackson-exception

关于java - 急流。如何在不渲染的情况下从 lambda 返回响应?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45782807/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com