|
From: Heiko W.R. <hr...@re...> - 2011-11-13 21:47:18
|
Hi,
I am running into those
Could not find MessageBodyWriter for response object of type: java.util.ArrayList of media type: application/xml
with whatever provider when I do
Response foo() {
List<MyType> x = new ArrayList<MyType>();
...
return Response.ok(x).build();
}
while
List<MyType> foo() {
List<MyType> x = new ArrayList<MyType>();
...
return x;
}
works like a charm.
While the latter is more obvious to write, I'd like to use the former to be able to pass additional info like
etags and so on.
Is this a known issue? Or am I just doing it wrong?
Thanks
Heiko
--
Reg. Adresse: Red Hat GmbH, Technopark II, Haus C,
Werner-von-Siemens-Ring 14, D-85630 Grasbrunn
Handelsregister: Amtsgericht München HRB 153243
Geschaeftsführer: Brendan Lane, Charlie Peters, Michael Cunningham, Charles Cachera
|
|
From: Xavier C. <xc...@gm...> - 2011-11-14 12:21:23
|
Hello Heiko,
Can you try with a GenericEntity wrapper to your list of domain entities ?
Response foo() {
GenericEntity<List<MyType>> x = new GenericEntity<List<MyType>>();
...
return Response.ok(x).build();
}
HTH
Best regards,
/Xavier
On Sun, Nov 13, 2011 at 10:47 PM, Heiko W.Rupp <hr...@re...> wrote:
> Hi,
>
> I am running into those
> Could not find MessageBodyWriter for response object of type:
> java.util.ArrayList of media type: application/xml
> with whatever provider when I do
>
> Response foo() {
> List<MyType> x = new ArrayList<MyType>();
> ...
> return Response.ok(x).build();
> }
>
> while
>
> List<MyType> foo() {
> List<MyType> x = new ArrayList<MyType>();
> ...
> return x;
> }
>
> works like a charm.
> While the latter is more obvious to write, I'd like to use the former to
> be able to pass additional info like
> etags and so on.
> Is this a known issue? Or am I just doing it wrong?
>
> Thanks
> Heiko
>
>
> --
> Reg. Adresse: Red Hat GmbH, Technopark II, Haus C,
> Werner-von-Siemens-Ring 14, D-85630 Grasbrunn
> Handelsregister: Amtsgericht München HRB 153243
> Geschaeftsführer: Brendan Lane, Charlie Peters, Michael Cunningham,
> Charles Cachera
>
>
>
> ------------------------------------------------------------------------------
> RSA(R) Conference 2012
> Save $700 by Nov 18
> Register now
> http://p.sf.net/sfu/rsa-sfdev2dev1
> _______________________________________________
> Resteasy-developers mailing list
> Res...@li...
> https://lists.sourceforge.net/lists/listinfo/resteasy-developers
>
--
Xavier
|
|
From: Heiko W.R. <hr...@re...> - 2011-11-14 12:52:39
|
Xavier, Am 14.11.2011 um 13:21 schrieb Xavier Coulon: > Can you try with a GenericEntity wrapper to your list of domain entities ? I could, but this sounds like a duct-tape approach. Especially since returning List<MyType> works. > Could not find MessageBodyWriter for response object of type: java.util.ArrayList of media type: application/xml > List<MyType> x = new ArrayList<MyType>(); I wonder if it has to do with the fact, that the MBW-selection code is searching for an ArrayList<X> and not List<X> to find a suitable MessageBodyWriter. While in the returning List<X> case, the code sees the return type of List<X> and does not have to guess. Perhaps for JAX-RS, Response could be enhanced to Response<T> so that there is no need to guess ? (Of course this does not help right now) Thanks Heiko -- Reg. Adresse: Red Hat GmbH, Technopark II, Haus C, Werner-von-Siemens-Ring 14, D-85630 Grasbrunn Handelsregister: Amtsgericht München HRB 153243 Geschaeftsführer: Brendan Lane, Charlie Peters, Michael Cunningham, Charles Cachera |
|
From: Bill B. <bb...@re...> - 2011-11-14 13:47:10
|
On 11/13/11 4:47 PM, Heiko W.Rupp wrote:
> Hi,
>
> I am running into those
> Could not find MessageBodyWriter for response object of type: java.util.ArrayList of media type: application/xml
> with whatever provider when I do
>
> Response foo() {
> List<MyType> x = new ArrayList<MyType>();
> ...
> return Response.ok(x).build();
> }
>
Its type erasure. Use GenericEntity as Xavier suggested. You are
probably marshalling JAXB? The problem is Resteasy can't determine the
type of the list by just passing it in as the generic type information
is not available.
It works in the other case:
List<MyType> foo() {
List<MyType> x = new ArrayList<MyType>();
...
return x;
}
Because the generic type information is available by introspecting the
method.
--
Bill Burke
JBoss, a division of Red Hat
http://bill.burkecentral.com
|
|
From: Heiko W.R. <hr...@re...> - 2011-11-14 14:01:32
|
Am 14.11.2011 um 14:47 schrieb Bill Burke: > Its type erasure. Use GenericEntity as Xavier suggested. You are Ok, I understand *sigh* > probably marshalling JAXB? The problem is Resteasy can't determine the > type of the list by just passing it in as the generic type information > is not available. Would it make sense to create some method level annotation (to include in JAX-RS 2.0) that conveys that type information? The GenericEntity may work perfectly, but is an ugly hack, that in my opinion obfuscates the code. Anyway thanks Xavier and Bill. Heiko -- Reg. Adresse: Red Hat GmbH, Technopark II, Haus C, Werner-von-Siemens-Ring 14, D-85630 Grasbrunn Handelsregister: Amtsgericht München HRB 153243 Geschaeftsführer: Brendan Lane, Charlie Peters, Michael Cunningham, Charles Cachera |
|
From: Bill B. <bb...@re...> - 2011-11-14 14:06:38
|
On 11/14/11 9:01 AM, Heiko W.Rupp wrote: > > Am 14.11.2011 um 14:47 schrieb Bill Burke: >> Its type erasure. Use GenericEntity as Xavier suggested. You are > > Ok, I understand *sigh* > >> probably marshalling JAXB? The problem is Resteasy can't determine the >> type of the list by just passing it in as the generic type information >> is not available. > > Would it make sense to create some method level annotation (to include in JAX-RS 2.0) > that conveys that type information? > The GenericEntity may work perfectly, but is an ugly hack, that in my opinion > obfuscates the code. > The same problem exists I believe. There's no way to do List<Foo>.class I don't htink. -- Bill Burke JBoss, a division of Red Hat http://bill.burkecentral.com |
|
From: Heiko W.R. <hr...@re...> - 2011-11-14 19:20:40
|
Am 14.11.2011 um 14:47 schrieb Bill Burke: > > Its type erasure. Use GenericEntity as Xavier suggested. You are > probably marshalling JAXB? The problem is Resteasy can't determine the > type of the list by just passing it in as the generic type information > is not available. What puzzles me though is that the json providers are able to correctly marshall the List<X> Heiko -- Reg. Adresse: Red Hat GmbH, Technopark II, Haus C, Werner-von-Siemens-Ring 14, D-85630 Grasbrunn Handelsregister: Amtsgericht München HRB 153243 Geschaeftsführer: Brendan Lane, Charlie Peters, Michael Cunningham, Charles Cachera |
|
From: Bill B. <bb...@re...> - 2011-11-14 21:08:49
|
On 11/14/11 2:20 PM, Heiko W.Rupp wrote: > > Am 14.11.2011 um 14:47 schrieb Bill Burke: > >> >> Its type erasure. Use GenericEntity as Xavier suggested. You are >> probably marshalling JAXB? The problem is Resteasy can't determine the >> type of the list by just passing it in as the generic type information >> is not available. > > What puzzles me though is that the json providers are able to correctly marshall the > List<X> > It is illegal to marshal a List in pure JAXB. :) Sure you can embed a list within an object, but on its own, nope. Plus this is a matching thing. Jackson will match anything. A Jaxb provider matches on whether or not a JAXB annotation is provided on the type. -- Bill Burke JBoss, a division of Red Hat http://bill.burkecentral.com |