-
Notifications
You must be signed in to change notification settings - Fork 28
Description
Hi I've tried using the nuget, but there is some weird behavior with collections. So I downloaded the code, there I found two issues:
-
The
return truein line 175 is redundant, causing all properties to be ignored. and results in an empty serialization data.
SharpSerializer/SharpSerializer/Advanced/PropertyProvider.cs
Lines 173 to 175 in 0781e02
{ return true; }
Removing these lines solved this issue. -
My issue with collections and references. When deserialized a collection that includes a reference to an object that was already added I got an exception with the following message:
Property type is not defined. Property: ""which is thrown here:
SharpSerializer/SharpSerializer/Deserializing/ObjectFactory.cs
Lines 82 to 87 in 0781e02
if (property.Type == null) { // there is no property type and no expected type defined. Give up! throw new InvalidOperationException(string.Format("Property type is not defined. Property: \"{0}\"", property.Name)); }
The reason for the exception is thatproperty.typeis not defined because in the xml string (I guess the same happens also with the binary serializer) there is no type defined for this property, and there shouldn't be one - because it was already defined for the reference object.
So my solution was to move the reference part:
var referenceTarget = property as ReferenceTargetProperty;
and
SharpSerializer/SharpSerializer/Deserializing/ObjectFactory.cs
Lines 100 to 108 in 0781e02
if (referenceTarget.Reference != null) { if (!referenceTarget.Reference.IsProcessed) { // object was created already // get object from cache return _objectCache[referenceTarget.Reference.Id]; } }
to before line 82 - this solved this issue.
So the new code looks like this:
// Is it NullProperty?
var nullProperty = property as NullProperty;
if (nullProperty != null)
{
return null;
}
var referenceTarget = property as ReferenceTargetProperty;
if (referenceTarget!=null && referenceTarget.Reference != null)
{
if (!referenceTarget.Reference.IsProcessed)
{
// object was created already
// get object from cache
return _objectCache[referenceTarget.Reference.Id];
}
}
if (property.Type == null)
{
// there is no property type and no expected type defined. Give up!
throw new InvalidOperationException(string.Format("Property type is not defined. Property: \"{0}\"",
property.Name));
}
// Is it SimpleProperty?
var simpleProperty = property as SimpleProperty;
if (simpleProperty != null)
{
return createObjectFromSimpleProperty(simpleProperty);
}
if (referenceTarget == null)
return null;
object value = createObjectCore(referenceTarget);
if (value != null)
return value;
I don't know how to upload these changes to the code, so I simply outlining this here.