Java – with restlets, xStream annotations don’t seem to have any effect
•
Java
Using @ xstreamomitfield in my POJO doesn't seem to have any impact Annotated fields are still exposed in XML or JSON representations
@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 serverresource
@Get
public Pojo test() {
Pojo pj= new Pojo("hansi","hinter");
return pj;
}
Get me
<com.myComp.ORMTest.Pojo> <name>hansi</name> <hidden>hinter</hidden> </com.myComp.ORMTest.Pojo>
Why are any comments ignored?
Solution
You must tell xStream to explicitly handle comments:
XStream xstream = new XStream(); xstream.processAnnotations(MyClass.class);
Alternatively, you should add this code to tell xStream to handle all comments:
xstream.autodetectAnnotations(true);
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码
