[jax-rs-spec users] [jsr339-experts] MessageBodyWriter Class parameter

From: Sergey Beryozkin <>
Date: Tue, 9 Oct 2012 13:49:09 +0100


I'd like to get some clarification on the Class parameter passed to MBR
isWriteable and writeTo.

The documentation suggests that it has to be an instance class, for
example, given

public Object getObject() {}

MBR will get MyObject1.class, MyObject2.class, etc

I've found though that in some cases it is awkward to get a provider
configured properly, for example,

public Book getBook() {
   if (something) {
      return SuperBook();
   } else {
      return SuperBook2();

The provider may need to customize the processing of all Book.class
instances, without getting the actual Book.class dependency, so with the
provider getting either SuperBook.class or SuperBook2.class instead of
Book is problematic - especially given that MBR writeTo() accepts the
actual Object - which can let the provider know about the actual
instance class.

I reckon in writeTo() it can make sense to get the return class reported
by a given method to pass directly to writeTo, so that the provider can
see that the first class parameter is 'Book.class', while the instance
class is object.getClass().

Thoughts ?