Jun 16, 2012 at 3:44 AM
Edited Jun 17, 2012 at 4:25 AM
|
Argh!! Im having the exact same problem.
I agree that this needs to be fixed, that the serializer is not behaving correctly.
According to MS documentation
[AttributeUsageAttribute(AttributeTargets.Class|AttributeTargets.Struct|AttributeTargets.Enum, Inherited = false,�AllowMultiple = false)]
http://msdn.microsoft.com/en-us/library/system.runtime.serialization.datacontractattribute(v=vs.95).aspx
DataContractAttribute should NOT be inherited from base types.The problem appears to be in JsonTypeReflector.GetDataContractAttribute - it forcefully traverses the inheritance hierarchy to root, to locate a DataContractAttribute.
public static DataContractAttribute GetDataContractAttribute(Type type)
{
// DataContractAttribute does not have inheritance
Type currentType = type;
while (currentType != null)
{
DataContractAttribute result = CachedAttributeGetter<DataContractAttribute>.GetAttribute(currentType.GetCustomAttributeProvider());
if (result != null)
return result;
currentType = currentType.BaseType();
}
return null;
}
I have written a simple resolver that takes care of it for me (and also a problem where Json.net now also uses custom typeconverters where possible, another breaking change for our ptoject). You can find it here:http://stackoverflow.com/questions/11044639/newtonsoft-json-serializer-returns-empty-object
|