Werner,
I have just found a post on the Internet where you were helping for a
similar issue.
I have followed some examples you gave, changed the mapping file and now
it works!
Here is my new mapping file:
<?xml version="1.0" encoding="UTF-8"?>
<mapping>
<class name="com.bluedot.common.action.component.ComponentData">
<map-to xml="component-data"/>
<field name="config" type="boolean">
<bind-xml name="config" node="attribute"/>
</field>
<field name="comp" type="java.lang.String">
<bind-xml name="comp" node="element"/>
</field>
<field name="hide" type="java.lang.Object" collection="arraylist">
<bind-xml name="hide" node="element"/>
</field>
<field name="others" collection="map">
<bind-xml name="others">
<class name="org.exolab.castor.mapping.MapItem">
<field name="key" type="string">
<bind-xml name="key" node="attribute" />
</field>
<field name="value" type="string">
<bind-xml name="value" node="text" />
</field>
</class>
</bind-xml>
</field>
<field name="msgs" collection="map">
<bind-xml name="msgs">
<class name="org.exolab.castor.mapping.MapItem">
<field name="key" type="string">
<bind-xml name="key" node="attribute" />
</field>
<field name="value" type="string">
<bind-xml name="value" node="text"/>
</field>
</class>
</bind-xml>
</field>
<field name="labels" collection="map">
<bind-xml name="labels">
<class name="org.exolab.castor.mapping.MapItem">
<field name="key" type="string">
<bind-xml name="key" node="attribute" />
</field>
<field name="value" type="string">
<bind-xml name="value" node="text"/>
</field>
</class>
</bind-xml>
</field>
</class>
</mapping>
this generates XML like this:
<?xml version="1.0" encoding="UTF-8"?>
<component-data config="false"><comp>summary</comp><others
key="extraAction">Housing Information</others><others
key="graphName">staff Registration Form</others><others
key="type">reg</others><others
key="extraActionEntity">show_institution_id</others><others
key="actionsHide">Assignment Details</others><others
key="listOnly">0</others></component-data>
The XML generated is much cleaner and the unmarshaller is able to get
the data back in the Java object.
No change was made to the Java Object class.
Thank you
Xav
Xav wrote:
I have a mapping.xml file that I used to marshall and unmarshall the
XML data, this file did not change.
<?xml version="1.0" encoding="UTF-8"?>
<mapping>
<class name="com.bluedot.common.action.component.ComponentData">
<map-to xml="component-data"/>
<field name="config" type="boolean">
<bind-xml name="config" node="attribute"/>
</field>
<field name="comp" type="java.lang.String">
<bind-xml name="comp" node="element"/>
</field>
<field name="hide" type="java.lang.Object" collection="arraylist">
<bind-xml name="hide" node="element"/>
</field>
<field name="others" type="java.lang.Object" collection="map">
<bind-xml name="others" node="element"/>
</field>
<field name="msgs" type="java.lang.Object" collection="map">
<bind-xml name="msgs" node="element"/>
</field>
<field name="labels" type="java.lang.Object" collection="map">
<bind-xml name="labels" node="element"/>
</field>
</class>
</mapping>
This mapping file was generated from the Object class below:
public class ComponentData implements Serializable {
private static final long serialVersionUID = 1L ;
private String comp;
private boolean config;
private HashMap<String,String> msgs ;
private HashMap<String,String> labels ;
private ArrayList<String> hide ;
private HashMap<String,String> others ;
public ComponentData() {
msgs = new HashMap<String,String>() ;
labels = new HashMap<String,String>() ;
others = new HashMap<String,String>() ;
hide = new ArrayList<String>() ;
}
public void setComp( String var ) {
this.comp = var ;
}
public String getComp() {
return this.comp ;
}
public void setConfig( boolean var ) {
this.config = var ;
}
public boolean getConfig() {
return this.config ;
}
public void setMsgs( HashMap<String,String> var ) {
this.msgs = var ;
}
public HashMap<String,String> getMsgs() {
return this.msgs ;
}
public void setLabels( HashMap<String,String> var ) {
this.labels = var ;
}
public HashMap<String,String> getLabels() {
return this.labels ;
}
public void setHide( ArrayList<String> var ) {
this.hide = var ;
}
public ArrayList<String> getHide() {
return this.hide ;
}
public void setOthers( HashMap<String,String> var ) {
this.others = var ;
}
public HashMap<String,String> getOthers() {
return this.others ;
}
}
By just adding these 2 lines to the marshaller the generated XML was
like this:
<?xml version="1.0" encoding="UTF-8"?>
<component-data
config="false"><comp>summary</comp><others><key>extraAction</key><value>Housing
Information</value></others><others><key>graphName</key><value>staff
Registration
Form</value></others><others><key>type</key><value>reg</value></others><others><key>extraActionEntity</key>
<value>show_institution_id</value></others><others><key>listOnly</key><value>0</value></others></component-data>
this is what I expected.
Now if I give this XML data to the unmarshaller with the same mapping
file, it is not populating the Java object ComponentData, but it was
before.
Let me know if you need more info.
Thank you for your help
Xav
Werner Guttmann wrote:
Sorry, but you'll need to be a bit more specific, in terms of XML
expected, Java entities, etc.
Werner
Xav wrote:
Hello,
The code I am developing marshalls an object to generate XML data and
another part unmarshall that XML code.
Everything was working fine until I added these 2 lines to the
marshaller:
marshaller.setSuppressXSIType( true ) ;
marshaller.setSuppressNamespaces( true ) ;
Now the unmarshall process does not populate the returned object with
the content of the XML.
Is there a way to get it to work without removing these 2 lines that
I'd
like to keep to shorten the XML generated?
I'm using the latest castor version.
Thank you
Xav
---------------------------------------------------------------------
To unsubscribe from this list please visit:
http://xircles.codehaus.org/manage_email
---------------------------------------------------------------------
To unsubscribe from this list please visit:
http://xircles.codehaus.org/manage_email
--
A person won't remember you by what you said,
but by how you made them feel.
---------------------------------------------------------------------
To unsubscribe from this list please visit:
http://xircles.codehaus.org/manage_email