[Jersey] Jersey, jaxb and Lists

From: Sigmar Muuga <>
Date: Wed, 27 Apr 2011 18:17:18 +0300


I have a class like this:
import java.util.List;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlElementRef;
import javax.xml.bind.annotation.XmlElementWrapper;
import javax.xml.bind.annotation.XmlRootElement;

 * Simple list info holder. Holds the filtered list and its total count
public class ListInfo<T> implements Serializable {

private static final long serialVersionUID = 1L;

@XmlElementWrapper(name = "items")
@XmlElement(name = "item")
private List<T> items = null;

private int totalCount;

public ListInfo() {


public ListInfo(List<T> list, int totalCount) {
this.items = list;
this.totalCount = totalCount;

public List<T> getItems() {
return items;

public void setItems(List<T> items) {
this.items = items;

public int getTotalCount() {
return totalCount;

public void setTotalCount(int totalCount) {
this.totalCount = totalCount;

And when I try to serialize it with jersey to JSON or XML, I get output like

    items: {
        item: [
    totalCount: "2"

The method in jersey resource is this:
public ListInfo<AreaInfo> findAllCountries() {
return service.findCountries();

Now the problem is, why is the list of items containing NULL-s? The item
classes themselves are also annotated as @XmlRootElement-s

Any ideas would be appreciated!

Best regards,