On 01/25/2011 03:39 PM, rocklee wrote:
> This can generate xml and json response well, but when I try to consume the
> resource using the code like following, it can fetch total, limit and page
> successfully, but the data is always empty.
I don't know if it that will help you, but here's my setup.
As I'm using Jersey in combination with Ext JS, I have something similar:
@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
@JsonAutoDetect(getterVisibility = Visibility.NONE, fieldVisibility =
Visibility.ANY)
@JsonWriteNullProperties(value = false)
public class ExtJsListWrapper<T> {
public List<T> data;
public Integer total;
}
Then, to make a request using Jersey client API, I use:
ExtJsListWrapper<MyObject> wrapper =
resource.accept(MediaType.APPLICATION_JSON_TYPE)
.type(MediaType.APPLICATION_JSON_TYPE)
.get(new GenericType<ExtJsListWrapper<MyObject>>() {});
List<MyObject> list = wrapper.data;
And it works just fine, the list is correctly populated.
The important part that I found is the "GenericType" magic, due to how
Java handles generics AFAIK.
Regards,
--
Damiano ALBANI