Problem de-serializing - Missing values

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Problem de-serializing - Missing values

emranrao
This post has NOT been accepted by the mailing list yet.
Trying to de-serialized the following XML, where "day" & "fulldob" are objects types with their individual converters for custom logic. Once De-serialized & when toXML method is applied to the object, the values for "day" & "fulldob" are missing. Meaning, day & fulldob are not getting de-serialized properly. I looked in the unmarsall method and tried to count the number of attributes for reader Object but it is zero. Seems like XStream is not liking these two be broken into their own Objects and/or with their individual converters. The converter for "day" is similar to "fulldob".
 
********** input XML *******
 <primarydob>
   <month>05</month>
   <day>13</day>
   <year>1982</year>
  <fulldob>19820513</fulldob>
 </primarydob>

**** XML from Object (after de-serializing the above XML) Missing values!! *******
  <primarydob>
   <month>05</month>
   <day/>
   <year>1982</year>
   <fulldob/>
 </primarydob>


***** Here's the object for "primarydob" ***********
@XStreamAlias("dob")  
public class DOBData {

  @XStreamAlias("month")
  private String month;

  @XStreamAlias("day")
  private DOBDay dobDay = new DOBDay();

  @XStreamAlias("year")
  private String year;

  @XStreamAlias("fulldob")
  private FullDOB fulldob = new FullDOB();

  getters/setters
}


******** Here's the object for "fulldob" ***********
@XStreamAlias("fulldobdata")
@XStreamConverter(FullDOBDayMaskingConverter.class)
public class FullDOB {

  @XStreamAlias("fulldob")
  private String fullDOB;

  public String getFullDOB() {
      return fullDOB;
  }

  public void setFullDOB(String fullDOB) {

      this.fullDOB = fullDOB;
  }
}


********** Here's the object for "day" ***********
@XStreamAlias("dobday")
@XStreamConverter(DOBDayMaskingConverter.class)
public class DOBDay {

  @XStreamAlias("day")
  private String day;

  public String getDay() {
         return day;
  }
  public void setDay(String day) {
         this.day = day;
  }
}

******************** FullDOB Converter *******************

public class FullDOBDayMaskingConverter implements Converter {

        public void marshal (Object bean, HierarchicalStreamWriter writer,MarshallingContext context)
        {
                FullDOB fullDob = (FullDOB) bean;

                if (fullDob.getFullDOB() != null && !fullDob.getFullDOB().equals(""))
                {
                         ..... custom logic
                }
        }

        public Object unmarshal(HierarchicalStreamReader reader,
                        UnmarshallingContext context)  
             {
            FullDOB fulldob = new FullDOB();
            while (reader.hasMoreChildren())
                 {
                     reader.moveDown();
                     if(reader.getNodeName().equals("fulldob"))
                     {
                   fulldob.setFullDOB(reader.getValue());
                     }
          reader.moveUp();
            }
            return fulldob;
        }

        public boolean canConvert(Class clazz) {
                return FullDOB.class.equals(clazz);
        }
}

 Can someone please help?

 Thanks,