我有一个休息网络服务。由于某种原因,我不想返回需要转换为接口(interface)的类。我想返回接口(interface),并且在 JSON 中我只想查看方法(开始获取)值。不是已实现类的所有属性。
举个例子:
@Path("getValues/")
@GET
@Produces( MediaType.APPLICATION_JSON)
public DetailInterface getClientDetail() {
return new DetailImpl();
}
并考虑界面:
public interface DetailInterface {
public String getName();
public String getAge();
}
并考虑实现
public class DetailImpl implements DetailInterface {
public String getName()
return "my name";
}
public String getAge(){
return "my age";
}
public String iDontWantThisinJSON() {
return "I don't want this in JSON output";
}
}
当我请求其余服务时,我看到 iDontWantThisinJSON
属性也出现在 JSON 响应中。我不想将其包含在回复中。
我该如何解决这个问题?
最佳答案
您尝试过@JsonIgnore
注释吗?将字段标记为 transient 也可能会有所帮助 - 但我不确定这是否可以。
关于java - Jersey 休息 : how to return interface instead of class,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30844563/