imulus/Archetype — pull request #153 by cankoluman (2014-06-20 11:06:57+00:00)
Title: Dev/ar 6 : Serialization bug fixes

Hi Kevin,

Sorry about the delay. This branch contains one fix - it should merge cleanly into your develop branch.

Fix -
(1) deal with empty archetype ```{"fieldsets": []}```

Relevant diff: (approximately...)
```csharp
--- a/app/Umbraco/Umbraco.Archetype/Serialization/ArchetypeJsonConverter.cs
+++ b/app/Umbraco/Umbraco.Archetype/Serialization/ArchetypeJsonConverter.cs
@@ -136,15 +136,15 @@ namespace Archetype.Serialization
if (objToken.SelectToken("properties") != null)
return PopulateProperties(obj, objToken["properties"]);

- if (objToken is JArray)
- {
- var defaultFsProperties = properties.Where(pInfo => !HasAsFieldsetAttribute(pInfo)).ToList();
+ if ((objToken is JArray) && (objToken as JArray).Count <= 0)
return null;

+ if (!(objToken is JArray))
+ return PopulateProperties(obj, new JArray(objToken));
+

- foreach (var property in defaultFsProperties)
- {
- var propJToken = ParseJTokenFromItems(objToken, GetJsonPropertyName(property));
- PopulateProperty(obj, propJToken["properties"], property);
- }
+ var defaultFsProperties = properties.Where(pInfo => !HasAsFieldsetAttribute(pInfo)).ToList();
+
+ foreach (var property in defaultFsProperties)
+ {
+ var propJToken = ParseJTokenFromItems(objToken, GetJsonPropertyName(property));
+ PopulateProperty(obj, propJToken["properties"], property);
}

return PopulateProperties(obj, new JArray(objToken));
```

And there are couple of new tests to check for this condition:
Umbraco/Archetype.Tests/Serialization/Regression/ArchetypeJsonConverterLegacySetUpTest
Umbraco/Archetype.Tests/Serialization/Regression/JsonTestLegacyModelSetUp.cs
Umbraco/Archetype.Tests/Serialization/Regression/JsonTestStrings.cs
Umbraco/Archetype.Tests/Serialization/Regression/ArchetypeJsonConverterTest.cs > EmptyArray_Returns_Null()

Cheers,