作者热门文章
- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我需要从 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();
这是有关该问题的一些信息, http://www.baeldung.com/jackson-exception
mapper.setVisibility(PropertyAccessor.FIELD, Visibility.ANY);
关于java - 急流。如何在不渲染的情况下从 lambda 返回响应?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45782807/
我是一名优秀的程序员,十分优秀!