Rest 如何通过jax-rs公开Java接口类型
我正在使用jax-rs的Jersey实现。我有一个由REST资源返回的域对象。看起来是这样的:Rest 如何通过jax-rs公开Java接口类型,rest,jaxb,jersey,jax-rs,Rest,Jaxb,Jersey,Jax Rs,我正在使用jax-rs的Jersey实现。我有一个由REST资源返回的域对象。看起来是这样的: @XmlRootElement @JsonSerialize(include=JsonSerialize.Inclusion.NON_NULL) @Data public class SomeObject implements Serializable { private static final long serialVersionUID = -3711391025272861884L; pri
@XmlRootElement
@JsonSerialize(include=JsonSerialize.Inclusion.NON_NULL)
@Data
public class SomeObject implements Serializable {
private static final long serialVersionUID = -3711391025272861884L;
private IInterface config;
@XmlElement
public IInterface getConfig() {
return config;
}
}
其中IInterface是一种Java接口类型
Jax-ws说炸弹爆炸了,说:
SomeObject的访问器null:接口类型不能是xml类型。->[帮助1]
我已经在谷歌上搜索过了,还不知道怎么做。如何告诉Jax ws如何处理此接口?您可以通过使用
@xmlement
注释指定具体的impl类型来映射属于接口类型的字段/属性:
@XmlRootElement
@JsonSerialize(include=JsonSerialize.Inclusion.NON_NULL)
@Data
public class SomeObject implements Serializable {
private static final long serialVersionUID = -3711391025272861884L;
private IInterface config;
@XmlElement(type=IInterfaceImpl.class)
public IInterface getConfig() {
return config;
}
}
了解更多信息
@xmlement
注释来指定具体的impl类型,从而映射接口类型的字段/属性:
@XmlRootElement
@JsonSerialize(include=JsonSerialize.Inclusion.NON_NULL)
@Data
public class SomeObject implements Serializable {
private static final long serialVersionUID = -3711391025272861884L;
private IInterface config;
@XmlElement(type=IInterfaceImpl.class)
public IInterface getConfig() {
return config;
}
}
了解更多信息