使用RESTlet,XStream注解似乎没有效果
在我的 POJO 中使用 @XStreamOmitField 似乎没有任何效果。带注释的字段仍然以 xml 或 json 表示形式公开。
@XStreamAlias("Pojo")
@Entity
public class Pojo {
private String name;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long key;
@XStreamOmitField
private String hidden;
public Pojo(String name, String hidden) {
this.name = name;
this.hidden = hidden;
}
}
在 ServerResource 中
@Get
public Pojo test() {
Pojo pj= new Pojo("hansi","hinter");
return pj;
}
让我
<com.myComp.ORMTest.Pojo>
<name>hansi</name>
<hidden>hinter</hidden>
</com.myComp.ORMTest.Pojo>
知道为什么注释被忽略?
Using @XStreamOmitField in my POJO seems to have no effect whatsoever. the annotated field still gets exposed in the xml or json representation.
@XStreamAlias("Pojo")
@Entity
public class Pojo {
private String name;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long key;
@XStreamOmitField
private String hidden;
public Pojo(String name, String hidden) {
this.name = name;
this.hidden = hidden;
}
}
and in the ServerResource
@Get
public Pojo test() {
Pojo pj= new Pojo("hansi","hinter");
return pj;
}
gets me
<com.myComp.ORMTest.Pojo>
<name>hansi</name>
<hidden>hinter</hidden>
</com.myComp.ORMTest.Pojo>
Any ideas why the annotations are ignored?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我想到两件事:
1.)您是否告诉 XStream 解析注释?
2.) 您的 Web 框架是否可能使用代理来访问 pojo,并且那些不委托注释? (发生在一位使用 Apache Tapestry 的朋友身上)
Two things come to mind:
1.) Did you tell XStream to parse the annotations?
2.) Does your web framework maybe use proxies to access the pojos and those don't delegate the annotations? (happened to a friend with Apache Tapestry)
您必须告诉 XStream 显式处理注释:
或者,您应该添加以下代码来告诉 XStream 处理所有注释:
You have to tell XStream to explicitly process annotations:
Or, you should add this code to tell XStream to process all annotations: