using RESTlet, XStream annotations seem to have no effect
Asked Answered
O

2

12

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?

Odds answered 20/2, 2010 at 0:40 Comment(3)
Ok, this seems to be not the only problem in getting GAE, RESTlet and XStream working together. I'm looking for another solution now.Odds
Hi, did the solution worked for you? How did you apply that? I'm having the same issues: #66794541Valuation
@fireburn , Sorry, I have no recollection of how I resolved the problem. This was 11 years ago.Odds
S
15

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);
Scrapbook answered 18/11, 2011 at 20:32 Comment(1)
Just a note for other seekers: auto detection of annotations only works for serialization, not deserialization. You have to process each class (or an array of them) in order to parse XML.Intercourse
E
2

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)

Embow answered 23/2, 2010 at 22:59 Comment(1)
Great leads. Will start digging in that direction. ThanksOdds

© 2022 - 2024 — McMap. All rights reserved.