Date serialization problem
I am serializing and deserializing an object and persisting the serialized XML into the database.
My class definition contains a date field.
However I have problems when I try to deserialize the xml back to my defined object. Its complaining that the serialized XML was in invalid format.
Here are my serialization and deserialization codes
public static T GetDeSerializedObj<T>(string strXML)
{
StringReader sr = new StringReader(strXML);
T result = default(T);
try
{
XmlSerializer serializer = new XmlSerializer(typeof(T));
result = (T)serializer.Deserialize(sr);
}
catch (FileNotFoundException)
{
result = default(T);
}
return result;
}
public static string GetSerializedXML<T>(T input)
{
StringBuilder sbOutput = new StringBuilder();
// XmlSerializer serializer = new XmlSerializer(typeof(T));
XmlSerializer serializer = new XmlSerializer(input.GetType());
using (StringWriter sw = new StringWriter(sbOutput))
{
serializer.Serialize(sw, input);
}
return sbOutput.ToString();
}
Here is the sample XML
<ClassInfo xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<DisplayID>1</DisplayID>
<ClassID>25</SubmissionID>
<CreatedTime>1800-01-01T00:00:00</CreatedTime>
<DateSubmitted>2007-07-13T10:14.9992703+08:00</DateSubmitted>
<ReceivedMessage />
</ClassInfo>
I noticed that the date submitted value is "2007-07-13T10:14.9992703+08:00" which should be 2007-07-13T10:14:00.9992703+08:00
for it to be a valid XML.
I tried to reproduce it by serializing a ClassInfo object with the seconds timefield set to 0 but I could not reproduce the error.
How is this possible?
"Dont you ever give up!"
__________________
\"Dont you ever give up!\"
|