Resteasy and JAXB: decide which xml properties to marshall
demetrio812 Jan 3, 2010 3:38 PMHi,
I'm giving a try to resteasy, everything works pretty well but I'm stuck on finding a good way to solve a very simple problem.
In my test I have a News entity which contains a title and a long description:
@Entity @Table(name = "news", catalog = "ifandango1") @XmlRootElement @XmlAccessorType(XmlAccessType.NONE) public class News implements java.io.Serializable { private Integer id; private String title; private String description; public News() { } @Id @GeneratedValue(strategy = IDENTITY) @Column(name = "id", unique = true, nullable = false) @XmlAttribute public Integer getId() { return this.id; } public void setId(Integer id) { this.id = id; } @Column(name = "title", nullable = false) @NotNull @XmlAttribute public String getTitle() { return this.title; } public void setTitle(String title) { this.title = title; } @Column(name = "description", nullable = false, length = 65535) @NotNull @Length(max = 65535) @XmlElement public String getDescription() { return this.description; } public void setDescription(String description) { this.description = description; } }
Then I have a Seam component that produces the XML:
@Name("newsRestResource") @Scope(ScopeType.EVENT) @Path("/news") public class NewsResource { @In(create = true) EntityManager entityManager; @In(create = true) NewsList newsList; @GET @Path("/data/{id}") @Produces("application/xml") public News getData(@PathParam("id") int id) { News news = entityManager.find(News.class, id); return news; } @GET @Path("/list") @Produces("application/xml") public News[] getList() { newsList.setOrderColumn("news.ordering"); newsList.setOrderDirection("asc"); newsList.setRestrictionLogicOperator("and"); final News[] result = newsList.getResultList().toArray(new News[]{}); return result; } }
Everything works but I would like that the xml list of the news doesn't contain the description field, is it possible using the annotations?
I looked on the net all the morning but never find a real example of that (isn't it a frequent use case?)
The only thing I tried is using another Entity for the same db table but I don't like this approach at all, I'm sure it is possible in a very simple way.
Any hint?
Thanks!
Dem