users@jax-rs-spec.java.net

[jax-rs-spec users] [jsr339-experts] Example 4: Why ReadInterceptors are cool

From: Bill Burke <bburke_at_redhat.com>
Date: Fri, 27 Apr 2012 12:21:11 -0400

This next example has to do with generically post processing a
unmarshaled Java Object. We have a @LinkHeader annotation that allows
use to inject a link into an unmarshalled entity.

@XmlRootElement
public class Customer
{

    @LinkHeader("image")
    Link image;

    @XmlAttribute
    String name;

...

}

We implement this as a a ReaderInterceptor as there is no way to do it
within a filter. This ReaderInterceptor is re-usable on the client and
the server.


Well, you *could* do it on the server-side, but it would depend on
whether or not a setEntity() method existed on server-side filter
context. This doesn't change the fact that you couldn't do it on the
client side and that a ReaderInterceptor wasn't a cleaner solution to
implement the feature.

-- 
Bill Burke
JBoss, a division of Red Hat
http://bill.burkecentral.com