Xml Serialization and additional nullable properties

Posts   
 
    
Posts: 134
Joined: 10-Jan-2007
# Posted on: 24-Jul-2007 17:31:38   

This is a follow up to http://www.llblgen.com/TinyForum/Messages.aspx?ThreadID=10271

The new code fixed the issue of serializing Nullable types but has brought to light a new issue. When WriteXml writes a Nullable property, they UnderlyingSystemType.FullName is the nullable type name which is correctly emitted as the "Type" attribute.

The full name is then passed to the XmlHelper.PropertyValueToString method as the valueTypeName which does not distinquish the underlying generic type correctly so if falls through the switch statement to the default and uses propertyValue.ToString.

In most cases this is probably not an issue, but with DateTime? it is outputing an invalid DateTime format (MM/dd/yyyy HH:mm am/pm) instead of converting to ticks. This is causing a problem on the ReadXml because it is passing the value to XmlConvert.ToDateTime which blows up with:

System.FormatException: The string '7/12/2007 12:00:00 AM' is not a valid AllXsd value. at System.Xml.Schema.XsdDateTime..ctor(String text, XsdDateTimeFlags kinds) at System.Xml.XmlConvert.ToDateTime(String s, XmlDateTimeSerializationMode dateTimeOption) at SD.LLBLGen.Pro.ORMSupportClasses.XmlHelper.XmlValueToObject(String typeName, String xmlValue) at SD.LLBLGen.Pro.ORMSupportClasses.EntityBase2.Xml2Entity(XmlNode node, Dictionary2 processedObjectIDs, List1 nodeEntityReferences) at SD.LLBLGen.Pro.ORMSupportClasses.EntityBase2.ReadXml(XmlNode node) at SD.LLBLGen.Pro.ORMSupportClasses.EntityBase2.ReadXml(XmlReader reader)

using .NET 2.0 runtime - 2.0.7.705

Anyway you can get the generic type and pass it into PropertyValueToString?

Brian Chance

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 25-Jul-2007 11:43:09   

What's the scenario in which you run into this, i.e.: in a webservice, or in manual xml write/read? If the latter, what are the format specs you set, i.e.: verbose, compact, datetime format etc.

Frans Bouma | Lead developer LLBLGen Pro
Posts: 134
Joined: 10-Jan-2007
# Posted on: 25-Jul-2007 15:38:54   

In a WebService, I have added some properties that are summaries instead of sending the data across the wire to calculate.

Brian

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 26-Jul-2007 10:49:28   

Thanks will check it out.

(edit) it is indeed the writer which goes wrong, it falls into the default: clause which simply produces a ToString() instead of the XML formatted datetime.

It should pass the datetime type to the routine. Will check it out where it goes wrong exactly.

Frans Bouma | Lead developer LLBLGen Pro
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 26-Jul-2007 12:18:46   

Fixed in next build. I've attached a new ORMSupportClasses build for v2.0

V2.5 already had this fixed as the code for xml serialization was rewritten.

Frans Bouma | Lead developer LLBLGen Pro
Posts: 134
Joined: 10-Jan-2007
# Posted on: 26-Jul-2007 15:13:49   

Thank you!

Is the xml serialization in 2.5 faster? Maybe I should upgrade...

Posts: 134
Joined: 10-Jan-2007
# Posted on: 26-Jul-2007 15:46:39   

The change looks to be working, but there is an interesting side effect. The type attribute of the nullable types is now output as just the underlying type, not the nullable type.

Following the code, I am not sure how it is converting the null values correctly. The type System.DateTime and an empty string would be passed into the XmlValueToObject method from Xml2Entity.

Maybe I should just switch to 2.5, what is the target release date?

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 26-Jul-2007 17:08:55   

Maybe I should just switch to 2.5, what is the target release date?

Very soon, in August I believe, and most probably very early in August.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 27-Jul-2007 10:32:00   

brianchance wrote:

Thank you!

Is the xml serialization in 2.5 faster? Maybe I should upgrade...

Much faster and much much more compact.

brianchance wrote:

The change looks to be working, but there is an interesting side effect. The type attribute of the nullable types is now output as just the underlying type, not the nullable type.

Following the code, I am not sure how it is converting the null values correctly. The type System.DateTime and an empty string would be passed into the XmlValueToObject method from Xml2Entity.

The type isn't in the XML for webservices:


<EntityCollection>
    <Entities>
    <OrderEntity OrderId="11008">
<NullableDateTime>2007-07-26T12:04:19.1556515+02:00</NullableDateTime>
<EntityReference PropertyName="Customers"/>
<EntityReference PropertyName="Shippers"/>
<EntityReference PropertyName="Employees"/>
<CompanyName/>
<NullableDec/>
etc.

NullableDec is null (it's a nullable decimal). I don't see type info in there. Are you now talking about verbose XML ? XmlValueToObject handles nullable types with empty strings nicely and sets them to null simple_smile

Frans Bouma | Lead developer LLBLGen Pro
Posts: 134
Joined: 10-Jan-2007
# Posted on: 27-Jul-2007 15:42:26   

I did not realize the WebService XML was the compact, that explains thatsmile

I do think there is still a problem with the non-compact version that outputs type information, it is outputting the base value type:

<snip> <TestDate Type="System.DateTime" /> <TestDec Type="System.Decimal" /> </snip>

When this is passed to ReadXml, it blows with "string is in incorrect format" since this type is passed directly to your helper routine.

Basically this blows up: entityXml = string.Empty; entity.WriteXml(out entityXml); Entity entity2 = new Entity(); entity2.ReadXml(entityXml);

Having said all that, my immediate problem is fixed and I will be upgrading to 2.5 soon to get the speed benefits.

The more I use this product the more I love it.

Brian

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 30-Jul-2007 10:05:16   

brianchance wrote:

I did not realize the WebService XML was the compact, that explains thatsmile

You did say it was in a webservice simple_smile Anyway, in v2.5 we introduced Compact25, which is as compact as you can possibly have it.

I do think there is still a problem with the non-compact version that outputs type information, it is outputting the base value type:

<snip> <TestDate Type="System.DateTime" /> <TestDec Type="System.Decimal" /> </snip>

When this is passed to ReadXml, it blows with "string is in incorrect format" since this type is passed directly to your helper routine.

Basically this blows up: entityXml = string.Empty; entity.WriteXml(out entityXml); Entity entity2 = new Entity(); entity2.ReadXml(entityXml);

Thanks, will look into it simple_smile

Having said all that, my immediate problem is fixed and I will be upgrading to 2.5 soon to get the speed benefits.

The more I use this product the more I love it. Brian

Thanks! smile

Frans Bouma | Lead developer LLBLGen Pro