I am trying to create some Java class from an XSD schema. I know exactly what I want to create in Java, and I'm trying to write an appropriate XSD schema.
I need to submit java.util.HashMap (HashMap). I cannot find how to indicate in the XSD schema (or xjb binding file) that I want HasMap in Java. It always generates a list.
here is the code i want to generate
@XmlAccessorType(XmlAccessType.FIELD) @XmlType(name = "ErrorMessage", propOrder = { "name", "details"}) public class ErrorMessage { @XmlElement(required = true) protected String name; @XmlElement(required = false) protected java.util.Map<String, String> details = new HashMap<String, String>();
I tried this:
<xsd:complexType name="ErrorMessage"> <xsd:sequence> <xsd:element name="name" type="xsd:string" /> <xsd:element name="details" type="map" /> </xsd:sequence> </xsd:complexType> <xsd:complexType name="map"> <xsd:sequence> <xsd:element name="mapEntry" type="mapEntry" minOccurs="0" maxOccurs="unbounded" /> </xsd:sequence> </xsd:complexType> <xsd:complexType name="mapEntry"> <xsd:sequence> <xsd:element name="key" type="xsd:string" /> <xsd:element name="value" type="xsd:string" /> </xsd:sequence> </xsd:complexType>
But it still continues to generate java.util.List of mapEntry:
In my Error class: protected Map details = new Map ();
Instead
protected java.util.Map<String, String> details = new HashMap<String, String>();
And the generated map class:
@XmlAccessorType(XmlAccessType.FIELD) @XmlType(name = "map", propOrder = {"mapEntry"}) public class Map { protected List<MapEntry> mapEntry;
I really need to use a map for my application. Any idea on how I can do this?
Note. I also tried using Oracle owi: hasmp , but got a namespace error.
xmlns:owi="http://www.oracle.com/webservices/internal" (also tried with xmlns:owi="http://www.oracle.com/webservices/internal/literal")
included in my schema ad
and my "details" element below
<xsd:element name="details" type="owi:hashmap" />
Mistake:
src-resolve.4.2: Error resolving the "owi: hasmap" component. it was discovered that "owi: hasmap" is in the namespace
' http://www.oracle.com/webservices/internal ', but the components from this namespace do not refer to the schema document 'File: //myFile.xsd. If this is an incorrect namespace, the prefix is' owi: hasmap' must be changed. If this is the correct namespace, then the corresponding "import" tag should be added to "File: //myFile.xsd
And it cannot bind "owi: hasmap" to a definition component of any type.
Any idea?