Hi Chris
On 19/06/12 15:23, Chris Geer wrote:
Is there a way to use the @ElementClass hint with returns that are List<>
or Arrays? I have a resource that I want the WADL to generate showing the
response element correctly and my methods return Response objects. On the
methods that return singular objects I can use @ElementClass( response =
Module.class) and the WADL will include the proper element in the response
section. I can't seem to get the same results with methods that return
List<String> or Module[]. I can define the Array one with @ElementClass(
response = Module[].class) but the element class in the WADL isn't present.
I can't even define the generic List approach.
Is there a way to handle this?
Not at the moment. Usually I recommend adding simple collection wrappers
which is better IMHO for a number of reasons, but I admit that explicit
collections will always be there in the method signatures...
The problem is how to get a JAXB compiler to generate a schema type and
element representing a collection wrapper.
For example, given a JAXB-annotated Module class, JAXB compiler will
generate the schema element and type. Similarly with a basic Modules
wrapper class. If we have List<Module>, the question is how to get the
compiler to produce a scheme element with, say, "modules" name.
If someone has an idea how to create a JAXBContext such that it
generates a proper schema for collections then we can do. I can only
think of using ASM to auto-generate such wrappers at the startup but it
won't work in cases where JAXBElementProvider is used to configure a
collection wrapper name
Cheers, Sergey
Examples:
This works great and the WADL includes the element.
@GET
@PATH("/module")
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
@ElementClass(response = Module.class)
public Response getModule() { ... }
This generates a WADL with a missing element tag
@GET
@PATH("/modules")
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
@ElementClass(response = Module[].class)
public Response getModules() { ... }
This just doesn't work at all since you can't get a class object from a
List like this (i.e. won't compile).
@GET
@PATH("/modules")
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
@ElementClass(response = List<Module>.class)
public Response getModules() { ... }
Module is a JAXB object that is generated from a schema.
Thanks,
Chris
--
Sergey Beryozkin
Talend Community Coders
http://coders.talend.com/
Blog: http://sberyozkin.blogspot.com