I found a lot of articles that describe how to unmarshal a sequence of XML elements to a HashMap as long as they are within a \"parent\" element. However, I do not get this to w
Note: I'm the EclipseLink JAXB (MOXy) lead and a member of the JAXB (JSR-222) expert group.
JAXB will treat each object relationship with a nesting relationship. Map
is treated like an Object
instead of a Collection
so this is why you are getting the behaviour that you are seeing.
MOXy has an XPath based mapping extension called @XmlPath
that could be used for this use case.
package com.foo.conf;
import java.util.Map;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
import org.eclipse.persistence.oxm.annotations.XmlPath;
@XmlRootElement(name="checks")
public class Checks {
@XmlJavaTypeAdapter(ChecksAdapter.class)
@XmlPath(".")
public Map checkMap;
}
For More Information