Hi, There's a setter on the Marshaller that allows you to turn off production of xsi:type statements. It would help you as your Map uses java.lang.Object as value type, which by default will require type information to be inserted into the generated XML.
Regards Werner [email protected] wrote: > Werner, > > How do you disable production of xsi:type instructions during marshalling? > Would this help me with my issue (java 5 enum xsi:type)? > > Thanks, > Niall > > > > > Werner Guttmann > <werner.guttmann@ > gmx.net> To > [email protected] > 12/18/2008 04:25 cc > PM > Subject > Re: [castor-user] Generic > Please respond to collection conversion and java > [email protected] types > aus.org > > > > > > > > > > David, > > what happens if you - when marshalling things out - disable production > of xsi:type instructions ? > > Werner > > david_geary wrote: >> I have a Java class containing a hash map field (that represents generic >> data). The values in the map could be common types such as string, date, >> boolean, integer etc. >> >> I also want to define an XML schema (ie the schema and Java are > pre-existing >> - im trying to write a mapping file between the two). >> >> The java class looks like this >> >> public class ExtensionDataSet >> { >> private int mId; >> private String mKey; >> private HashMap<String, Object> mDataMap; >> >> public int getId() >> {return mId;} >> public void setId(int id) >> {mId = id;} >> public String getKey() >> {return mKey;} >> public void setKey(String key) >> {mKey = key;} >> public HashMap<String, Object> getDataMap() >> {return mDataMap;} >> public void setDataMap(HashMap<String, Object> dataMap) >> {mDataMap = dataMap;} >> } >> >> Using this mapping file >> >> <mapping> >> <class name="com.abc.ExtensionDataSet"> >> <map-to xml="extension" ns-uri=" > http://www.abc.com/schemas/core"/> >> <field name="id" type="int"> >> <bind-xml name="id" node="attribute"/> >> </field> >> >> <field name="key" type="string"> >> <bind-xml name="key" > node="attribute"/> >> </field> >> >> <field name="dataMap" collection="map"> >> <bind-xml name="extension-field" > node="element" /> >> </field> >> </class> >> >> <class name="org.exolab.castor.mapping.MapItem"> >> <map-to xml="extension-field" >> ns-uri="http://www.abc.com/schemas/core"/> >> >> <field name="key" type="other"> >> <bind-xml name="key" node="attribute"/> >> </field> >> >> <field name="value" type="string"> >> <bind-xml node="element"/> >> </field> >> </class> >> >> >> </mapping> >> >> I can get a castor to marshal the class to of the form: >> >> <core:extension xmlns:core="http://www.abc.com/ecm/schemas/core" id="5" >> key="testkey"> >> <core:extension-field key="key1"> >> <core:value>value1</core:value> >> </core:extension-field> >> <core:extension-field key="key3"> >> <core:value xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" >> xsi:type="date">2008-12-17T18:18:33.066Z</core:value> >> </core:extension-field> >> <core:extension-field key="key2"> >> <core:value xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" >> xsi:type="java:java.lang.Integer">1</core:value> >> </core:extension-field></core:extension> >> >> However this isn't generic enough for our needs - we don't want any > mention >> of java in the generated XML (the point of going to XML is to be >> implementation language neutral - see >> http://jira.codehaus.org/browse/CASTOR-769 ) >> >> My question is how to do this without references to the java types but >> maintaining the type information in the XML. I can see two ways to do > this >> 1) Use XML types in the xsi:types part of the generated XML above. Castor >> already has standard mapping between XML and Java types so is it possible > to >> set a flag in castor to tell it not to refer to java in the XML and use > its >> standard mapping instead? ie like it seems to do for date? >> >> 2) Use a choice construct in the XSD we will write that allows values in > the >> XML document to be either <string-value>, <boolean-value> etc and > therefore >> the types would be enforced in the XML schema for these - ie we would > want >> to generate XML of the form: >> >> <core:extension xmlns:core="http://www.abc.com/ecm/schemas/core" id="5" >> key="testkey"> >> <core:extension-field key="key1"> >> <core:string-value>value1</core:string-value> >> </core:extension-field> >> <core:extension-field key="key3"> >> <core:date-value>2008-12-17T18:18:33.066Z</core:date-value> >> </core:extension-field> >> <core:extension-field key="key2"> >> <core:integer-value>1</core:integer-value> >> </core:extension-field></core:extension> >> >> I actually prefer the second option here and am wondering is there ANY > way >> to do this in Castor - ie the <bind-xml name> part of the mapping for the >> values in the hash map would be different depending on the type of the > value >> object. >> >> If this isn't possible right now - are there any obvious extension points > i >> should be looking at in castor? All the logic seems to be in the > Marshaller >> and Unmarshaller classes? >> >> Thanks for any help >> >> Dave >> > > --------------------------------------------------------------------- > To unsubscribe from this list, please visit: > > http://xircles.codehaus.org/manage_email > > > > > > ----------------------------------------- > CONFIDENTIALITY STATEMENT: > This e-mail transmission contains information that is intended to > be confidential. It is intended only for the addressee named > above. If you receive this e-mail in error, please do not read, > copy, or disseminate it. If you are not the intended recipient, > any disclosure, copying, distribution or use of the contents of > this information is prohibited. Please reply to the message > immediately by informing the sender that the message was > misdirected. After replying, please erase it from your computer > system. Your assistance in correcting this error is appreciated. > --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email

