Jonathan-

Unfortunately, I don't think there is anyway to change the element
name for "primitive" classes (for the most part Castor treats Strings
as primitives).  Normally how you would do this is create a simple
mapping that defined <map-to> in order to change the element name, but
as I found out recently on an unrelated investigation, Castor doesn't
even look for class mappings for primitive classes.  My next best
thought would be XSLT...  Sorry I can't be of more help.

Stephen


On 4/4/06, Jonathan Bryant <[EMAIL PROTECTED]> wrote:
>
>
>
> 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) ;
>
> }
>
>
>
>
>
>
>
>
>
>

Reply via email to