diff --git a/Serialiser_Engine/Compute/Deserialise.cs b/Serialiser_Engine/Compute/Deserialise.cs index d7b01a368..108355dce 100644 --- a/Serialiser_Engine/Compute/Deserialise.cs +++ b/Serialiser_Engine/Compute/Deserialise.cs @@ -53,7 +53,12 @@ private static object IDeserialise(this BsonValue bson, string version, bool isU if (bson.IsBsonNull) return null; else if (bson.IsBsonArray) - return bson.DeserialiseList(new List(), version, isUpgraded); + { + if (IsNestedList(bson)) + return bson.DeserialiseNestedList(new List>(), version, isUpgraded); + else + return bson.DeserialiseList(new List(), version, isUpgraded); + } else if (bson.IsBsonDocument) { BsonDocument doc = bson.AsBsonDocument; diff --git a/Serialiser_Engine/Compute/Deserialise/List.cs b/Serialiser_Engine/Compute/Deserialise/List.cs index 7c595bad9..baaeb7226 100644 --- a/Serialiser_Engine/Compute/Deserialise/List.cs +++ b/Serialiser_Engine/Compute/Deserialise/List.cs @@ -56,5 +56,39 @@ private static List DeserialiseList(this BsonValue bson, List value, st } /*******************************************/ + + private static List> DeserialiseNestedList(this BsonValue bson, List> value, string version, bool isUpgraded) + { + bson = ExtractValue(bson); + + if (!bson.IsBsonArray) + { + BH.Engine.Base.Compute.RecordError("Expected to deserialise a List and received " + bson.ToString() + " instead."); + return value; + } + + if (value == null) + value = new List>(); + + foreach (BsonValue item in bson.AsBsonArray) + value.Add((List)item.DeserialiseList(new List(), version, isUpgraded)); + + return value; + } + + /*******************************************/ + + private static bool IsNestedList(this BsonValue bson) + { + int nest = 0; + + while(bson.IsBsonArray) + { + nest++; + bson = bson[0]; + } + + return nest > 1; + } } }