Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

using RESTlet, XStream annotations seem to have no effect

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?

like image 867
chaos0815 Avatar asked Feb 20 '10 00:02

chaos0815


1 Answers

You have to tell XStream to explicitly process annotations:

XStream xstream = new XStream();
xstream.processAnnotations(MyClass.class);

Or, you should add this code to tell XStream to process all annotations:

xstream.autodetectAnnotations(true);
like image 131
superdave Avatar answered Sep 23 '22 00:09

superdave