Q:

Storing List with XStream with defined names

I want to store some class to xml:
    XStream xstream = new XStream(new DomDriver());

    List<String> modules = new ArrayList<String>();
    modules.add("mod1");
    modules.add("mod2");
    ModulesConfig modulesConfig = new ModulesConfig(modules);

xstream.processAnnotations(ModulesConfig.class);
log.info(xstream.toXML(modulesConfig));

Class ModulesConfig:
@XStreamAlias("modules-config")
public class ModulesConfig {

    @XStreamAlias("moduleName")
    private List<String> moduleNames;

    public ModulesConfig(List<String> moduleNames) {
        this.moduleNames = moduleNames;
    }

    public List<String> getModuleNames() {
        return moduleNames;
    }

    public void setModuleNames(List<String> moduleNames) {
        this.moduleNames = moduleNames;
    }
}

Result:
<modules-config>
  <moduleName>
    <string>mod1</string>
    <string>mod2</string>
  </moduleName>
</modules-config>

But I want elements were named "moduleName". How to configure xstream or what annotations I must to add to class? I want such result:
<modules-config>
  <moduleNames>
    <moduleName>mod1</moduleName>
    <moduleName>mod2</moduleName>
  </moduleNames>
</modules-config>

A:

This won't have the exact result as you requested but seems cleaner:
@XStreamImplicit(itemFieldName="moduleName")
private List<String> moduleNames;

The produced result will be:
<modules-config>
  <moduleName>mod1</moduleName>
  <moduleName>mod2</moduleName>
</modules-config>

