users@jersey.java.net

Transform list of xml elements into JSONArray

From: Martin Grotzke <martin.grotzke_at_javakaffee.de>
Date: Mon, 24 Mar 2008 04:36:42 +0100

Hi,

what would be the best way to transform an Items root element containing
a list of Item elements into a JSONArray?

This is the (generated) Items bean:

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "items", propOrder = {
    "items"
})
@XmlRootElement(name = "items")
public class Items {

    @XmlElement(name = "item")
    protected List<String> items;

    ...
}

The expected json is s.th. like that:

["val 1", "val 2", "val 3"]

This is desired to support a firefox suggestion search plugin ([1]).

It would be nice if I could return an instance of items, so that both
xml and json would be supported...

Thanx for your help,
cheers,
Martin


[1] http://developer.mozilla.org/en/docs/Supporting_search_suggestions_in_search_plugins