iLearn,
By default Castor will marshal/unmarshal with "-" in between the words, so MyObject will get marshaled into "my-object", since that is a default behavior.
In order to create a "custom look" for your object and fields, you would need to create a mapping file - which is really not all that difficult. Here is a great example from: http://www.castor.org/xml-mapping.html
Let's say you have a class OrderItem:
Code:
public class OrderItem {
private String id;
private Integer orderQuantity;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public Integer getOrderQuantity() {
return orderQuantity;
}
public void setOrderQuantity(Integer orderQuantity) {
this.orderQuantity = orderQuantity;
}
}
normally, if you map it with Castor without any mapping file, you would get:
Code:
<?xml version="1.0" ?>
<order-item>
<id>12</id>
<order-quantity>100</order-quantity>
</order-item>
but what if you need to marshal it (map it) to something like this which is way more natural and more readable:
Code:
<?xml version="1.0" ?>
<item identity="12">
<quantity>100</quantity>
</item>
then you need to create a very simple mapping file:
Code:
<class name="mypackage.OrderItem>
<map-to xml="item"/>
<field name="id" type="string">
<bind-xml name="identity" node="attribute"/>
</field>
</field name="orderQuantity" type="integer">
<bind-xml name="quantity" node="element"/>
</field>
</class>
It is very simple - you map:
"OrderItem" to "item"
"id" to "identity" (and making it an attribute by: node="attribute")
"orderQuantity" to "quantity"
from here: http://blog.dotkam.com/2008/06/25/ma...l-with-castor/
litius