I have something like
@XmlElementWrapper(name=\"Mylist\")
List myItems = new ArrayList()
and that comes out lik
Here's an XmlAdapter
to handle comma separated lists:
import java.util.ArrayList;
import java.util.List;
import javax.xml.bind.annotation.adapters.XmlAdapter;
public class CommaSeparatedListAdapter extends XmlAdapter> {
@Override
public List unmarshal(final String string) {
final List strings = new ArrayList();
for (final String s : string.split(",")) {
final String trimmed = s.trim();
if (trimmed.length() > 0) {
strings.add(trimmed);
}
}
return strings;
}
@Override
public String marshal(final List strings) {
final StringBuilder sb = new StringBuilder();
for (final String string : strings) {
if (sb.length() > 0) {
sb.append(", ");
}
sb.append(string);
}
return sb.toString();
}
}
You would use it like this:
@XmlElementWrapper(name="Mylist")
@XmlJavaTypeAdapter(CommaSeparatedListAdapter.class)
List myItems = new ArrayList()