|
Hi, I’m having trouble dealing with heterogenous
collections using castor-xml. I have a request class which contains a map of
parameters. The map key represents the name of the parameter. The value can be anything.
I’ve got it working, but simple values like Strings, longs, etc. are
being returned as <String>foo</String>. Is there a way to suppress
the class name for some classes, or is there a better way to do this? Here’s my mapping: <mapping> <class name="InsightsText"> <map-to xml="insightsText"/> <field name="textType"> <bind-xml name="typeName"
node="attribute"/> </field> <field name="text"> <bind-xml node="text"/> </field> </class> <class name="DefaultRequest"> <map-to xml="request"/> <field name="parameters"
collection="map"> <bind-xml name="parameter"
node="element"> <class
name="org.exolab.castor.mapping.MapItem"> <field name="key"
type="string"> <bind-xml name="name"
node="attribute"/> </field> <field name="value" type="java.lang.Object"> <bind-xml
node="element" auto-naming="deriveByClass"/> </field> </class> </bind-xml> </field> </class> </mapping> Here’s the result I’m getting. <?xml version="1.0"
encoding="UTF-8"?> <request> <parameter name="foo"> <long
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:type="java:java.lang.Long">1</long> </parameter> <parameter name="bar"> <insightsText
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
textType="insert"xsi:type="insightsText">efg</insightsText> </parameter> <parameter name="test"> <string xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:type="java:java.lang.String">abc</string> </parameter> </request> Here’s the outline of the classes public class Request { public Map getParameters(); public void setParameters(Map parameters); } public class InsightsText { public String getText() ; public void setText(String text) ; public String getTextType() ; public void setTextType(String textType) ; } |
- [castor-user] Mapping heterogenous collection Jonathan Bryant
- Re: [castor-user] Mapping heterogenous collection Stephen Bash

