如何在Play框架中禁用序列化?

问题描述 投票:0回答:1

我正在使用Play Frameworkmorphia来部署REST服务。我在Object响应中传递Generic Jackson时收到以下错误

Caused by: com.fasterxml.jackson.databind.JsonMappingException: No serializer found for class java.lang.Object and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationFeature.FAIL_ON_EMPTY_BEANS) (through reference chain: common.ResponseStatusEntity["data"]->entities.Trainer["appointmentNotificaiton"]->entities.notificaitons.AppointmentNotificaiton["data"])

如何在play框架中禁用Serializer验证?

java json playframework jackson sbt
1个回答
0
投票

问题是Object没有任何属性,默认情况下Jackson不接受它。要禁用它,您需要配置ObjectMapper,如下所示:

ObjectMapper mapper = new ObjectMapper();
mapper.disable(SerializationFeature.FAIL_ON_EMPTY_BEANS);

但马赫更好的是返回某种SUCCESS对象,明确告诉一切都是OK

© www.soinside.com 2019 - 2024. All rights reserved.