diff --git a/uSync8.ContentEdition/Mapping/Mappers/NestedContentMapper.cs b/uSync8.ContentEdition/Mapping/Mappers/NestedContentMapper.cs index 5c34a070..3c8dc3e4 100644 --- a/uSync8.ContentEdition/Mapping/Mappers/NestedContentMapper.cs +++ b/uSync8.ContentEdition/Mapping/Mappers/NestedContentMapper.cs @@ -30,10 +30,7 @@ public NestedContentMapper( public override string GetExportValue(object value, string editorAlias) { - var stringValue = GetValueAs(value); - if (string.IsNullOrWhiteSpace(stringValue) || !stringValue.DetectIsJson()) return value.ToString(); - - var nestedJson = JsonConvert.DeserializeObject(stringValue); + var nestedJson = GetItemArray(value); if (nestedJson == null || !nestedJson.Any()) return value.ToString(); foreach (var item in nestedJson.Cast()) @@ -49,11 +46,7 @@ public override string GetExportValue(object value, string editorAlias) public override IEnumerable GetDependencies(object value, string editorAlias, DependencyFlags flags) { - var stringValue = GetValueAs(value); - if (string.IsNullOrWhiteSpace(stringValue) || !stringValue.DetectIsJson()) - return Enumerable.Empty(); - - var nestedJson = JsonConvert.DeserializeObject(stringValue); + var nestedJson = GetItemArray(value); if (nestedJson == null || !nestedJson.Any()) return Enumerable.Empty(); @@ -77,6 +70,21 @@ public override IEnumerable GetDependencies(object value, strin return dependencies; } + + private JArray GetItemArray(object value) + { + var stringValue = GetValueAs(value); + if (string.IsNullOrWhiteSpace(stringValue) || !stringValue.DetectIsJson()) + return null; + + var token = JToken.Parse(stringValue); + switch (token) + { + case JArray array: return array; + case JObject obj: return new JArray(obj); + default: return null; + } + } } } diff --git a/uSync8.ContentEdition/Mapping/SyncNestedValueMapperBase.cs b/uSync8.ContentEdition/Mapping/SyncNestedValueMapperBase.cs index 342c3f1f..e7cbe617 100644 --- a/uSync8.ContentEdition/Mapping/SyncNestedValueMapperBase.cs +++ b/uSync8.ContentEdition/Mapping/SyncNestedValueMapperBase.cs @@ -137,10 +137,14 @@ protected JObject GetJsonValue(object value) var stringValue = GetValueAs(value); if (string.IsNullOrWhiteSpace(stringValue)) return null; - var jsonValue = JsonConvert.DeserializeObject(stringValue); - if (jsonValue == null) return null; + var token = JToken.Parse(stringValue); - return jsonValue; + switch(token) + { + case JObject obj: return obj; + case JArray array: return array.FirstOrDefault().ToObject(); + default: return null; + } } protected IContentType GetDocType(JObject json, string alias)