- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
希望将具体类连接到 blueprint.xml
中 REST 服务器的 @POST
方法的参数。
Jackson 数据绑定(bind)找不到该方法的 send
参数的具体实现。
REST 服务器有一个 send
方法,定义为:
public interface NotificationServer {
@POST
Response send(NotificationRequest notificationRequest);
}
NotificationRequest
也是一个接口(interface):
public interface NotificationRequest {
NotificationServer
的具体实现称为 EmailNotificationServerImpl
,它实现了该接口(interface):
public class EmailNotificationServerImpl implements NotificationServer {
@Override
public Response send(final NotificationRequest request) {
blueprint.xml
的相关部分包括:
<bean class="EmailNotificationServerImpl" id="emailNotificationServerImpl">...</bean>
<bean class="NotificationRequestImpl" id="notificationRequestImpl" />
<service interface="NotificationRequest" ref="notificationRequestImpl" />
jackson 错误消息:
Caused by: com.fasterxml.jackson.databind.JsonMappingException: Can not construct instance of NotificationRequest: abstract types either need to be mapped to concrete types, have custom deserializer, or contain additional type information
可以使用以下方法反序列化该类:
@JsonDeserialize(as = NotificationRequestImpl.class)
public interface NotificationRequest {
虽然这有效,但它并没有将实现与接口(interface)完全解耦。
如何将具体实现连接到 blueprint.xml
中,以便不需要 @JsonDeseralize
注释?
最佳答案
使用扩展 JacksonJsonProvider 的自定义提供程序在 <jaxrs:providers>
内的 JAX-RS 服务器定义中标签。
或者使用扩展 StdSerializer 的自定义反序列化器:
@JsonDeserialize(using = YourDeserializer.java)
或者使用多态性和 @JsonTypeInfo
+ @JsonSubtypes
注释。
关于java - 将具体实现连接到 blueprint.xml 中的接口(interface),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52448683/
我正在开发一个 voip 调用应用程序。我需要做的是在接到来电时将 Activity 带到前台。我在应用程序中使用 Twilio,并在收到推送消息时开始调用。 问题是我试图在接到任何电话时显示 Act
我是一名优秀的程序员,十分优秀!