wink-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Bryant Luk <>
Subject Re: Question on JAXB ID resolver
Date Mon, 02 Nov 2009 20:23:30 GMT
Hi Ajiyos,

You will need to write your own entity provider in this case (although
you can set properties on the marshalling side, the unmarshalling does
not currently).  If you want this feature, please open a JIRA against
Apache Wink ( for future
consideration as time permits.

If you want a solution immediately, you can look at the source for our
JAXB XML providers here and base your solution on them:

For instance, you could write something like:

public MyXmlProvider implements MessageBodyReader<Object> {

    public boolean isReadable(Class<?> type,
                              Type genericType,
                              Annotation[] annotations,
                              MediaType mediaType) {
        return isJAXBObject(type, genericType) &&

    public Object readFrom(Class<Object> type,
                           Type genericType,
                           Annotation[] annotations,
                           MediaType mediaType,
                           MultivaluedMap<String, String> httpHeaders,
                           InputStream entityStream) throws
IOException, WebApplicationException {
        Unmarshaller unmarshaller = null;
        Object unmarshaledResource = null;
        try {
            JAXBContext context = getContext(type, mediaType);
            unmarshaller = context.createUnmarshaller();
            // set something here
            unmarshaller.setProperty(..., ...);
            if (type.isAnnotationPresent(XmlRootElement.class))
                unmarshaledResource = unmarshaller.unmarshal(entityStream);
                unmarshaledResource =
StreamSource(entityStream), type).getValue();
        } catch (JAXBException e) {
            throw new WebApplicationException(e, Response.Status.BAD_REQUEST);
        return unmarshaledResource;

    protected boolean isSupportedMediaType(MediaType mediaType) {
        return MediaTypeUtils.isXmlType(mediaType);

    public static boolean isJAXBObject(Class<?> type, Type genericType) {
        return isXMLRootElement(type) || isXMLType(type);

Add MyXmlProvider to your JAX-RS Application subclass in the
getClasses() method (or your wink-application config file).

I would copy whatever you want out of the Wink source (i.e. don't
extend from the internal code) to make sure your code works in future.

2009/11/2 അജിയോസ്‌ യോഹന്നാന്‍(Ajiyos) <>:
> I didnt get any response in user group. Trying my luck here.
> ---------- Forwarded message ----------
> From: അജിയോസ്‌ യോഹന്നാന്‍(Ajiyos) <>
> Date: 2009/11/2
> Subject: Question on JAXB ID resolver
> To:
> Hi,
> Can any one tell me how to hookup my custom IDResolver to wink framework.
> The IDResolver need to be configured as a property to my jaxb unmarshaller.
> However I coudnt find out how to get handle to unmarshaller.
> Thanks,
> Ajiyos
> --
> "Attitude not the Aptitude determines the Altitude"
> --
> "Attitude not the Aptitude determines the Altitude"

View raw message