Title: Message
Hi guys,
   I tried castor to marshal a detail object into the xml stream. It was successful but it could not cater to
needs like non basic datatype which are as attribute inside a container class. Please look at the example
which i am attaching with this mail.
 
I am here by jotting down my requirements:
  1. XML Serializer should be able to convert all attribute irrespective whether they are of basic datatype or other wise.
  2. Should also represent the null data also in the serialized XML file.
  3. If should also shows the attribute type in the xml.
 
Please suggest me how these could be attained using castor....
 
Thanks,
Souravmay Das
 
To explain this scenario I am giving a sample application along with this mail
 
DETAIL OBJECT:
  a container class containing another detail object of type Detail2,String and of basic-type long
public class Detail {
    private String str;
    private long longNumber;
    private Detail2 detail; 
    public String getStr() {
        return str;
    }
    public void setStr(String str) {
        this.str = str;
    }
    public long getLongNumber() {
        return longNumber;
    }
    public void setLongNumber(long longNumber) {
        this.longNumber = longNumber;
    }
    public Detail2 getDetail() {
        return detail;
    }
    public void setDetail(Detail2 detail) {
        this.detail = detail;
    }
}
 
Detail2 detail object:
public class Detail2 {
    private Long veryLong;
 
    public Long getVeryLong() {
        return veryLong;
    }
 
    public void setVeryLong(Long veryLong) {
        this.veryLong = veryLong;
    }
}
 
Serilization class:
    public static void main(String [] str) throws Exception{
        Detail detail = new Detail();
        detail.setLongNumber( 213120L );
        Detail2 detail2 = new Detail2();
        detail2.setVeryLong( new Long(12312L) );
        StringWriter writer=new StringWriter();
        Marshaller marshal = new Marshaller(writer);
        marshal.marshal(detail);
        System.out.println( "" + writer.toString() );
    }
 
OUTPUT OBTAINED:
<?xml version="1.0" encoding="UTF-8"?>
<detail>
    <longNumber>
        213120
    </longNumber>
</detail>
 
Desired output should ideally be:
<detail type="tavant.Detail">
    <longNumber type="long">213120</longNumber>
    <str type="String" null="true" />
    <detail type="tavant.Detail2">
        <veryLong type="java.lang.Long" >
            12312
        </veryLong>
   </detail>
</detail>
 
Please let me know is there a way to attain such out put and please note deserialization back to object should also work...
 
Any idea ??? how to make this thing work...
Thanks,
  -Souravmay Das
 

Reply via email to