Permalink
Browse files

Merge remote-tracking branch 'origin/HEAD'

  • Loading branch information...
2 parents 260d0f3 + b68a5ad commit c52fd496c34599fc9cecee8b66d803b5843abd85 @mythz mythz committed Apr 11, 2012
@@ -239,6 +239,9 @@
<Compile Include="..\ServiceStack.Text\Support\TypePair.cs">
<Link>Support\TypePair.cs</Link>
</Compile>
+ <Compile Include="..\ServiceStack.Text\SystemTime.cs">
+ <Link>SystemTime.cs</Link>
+ </Compile>
<Compile Include="..\ServiceStack.Text\TextExtensions.cs">
<Link>TextExtensions.cs</Link>
</Compile>
@@ -237,6 +237,9 @@
<Compile Include="..\ServiceStack.Text\Support\TypePair.cs">
<Link>Support\TypePair.cs</Link>
</Compile>
+ <Compile Include="..\ServiceStack.Text\SystemTime.cs">
+ <Link>SystemTime.cs</Link>
+ </Compile>
<Compile Include="..\ServiceStack.Text\TextExtensions.cs">
<Link>TextExtensions.cs</Link>
</Compile>
@@ -86,7 +86,13 @@ public static T[] ParseGenericArray(string value, ParseStringDelegate elementPar
var elementValue = Serializer.EatValue(value, ref i);
var listValue = elementValue;
to.Add((T)elementParseFn(listValue));
- Serializer.EatItemSeperatorOrMapEndChar(value, ref i);
+ if(Serializer.EatItemSeperatorOrMapEndChar(value, ref i)
+ && i == valueLength)
+ {
+ // If we ate a separator and we are at the end of the value,
+ // it means the last element is empty => add default
+ to.Add(default(T));
+ }
}
return to.ToArray();
@@ -138,7 +138,13 @@ public static ICollection<T> ParseGenericList(string value, Type createListType,
var elementValue = Serializer.EatValue(value, ref i);
var listValue = elementValue;
to.Add((T)parseFn(listValue));
- Serializer.EatItemSeperatorOrMapEndChar(value, ref i);
+ if (Serializer.EatItemSeperatorOrMapEndChar(value, ref i)
+ && i == valueLength)
+ {
+ // If we ate a separator and we are at the end of the value,
+ // it means the last element is empty => add default
+ to.Add(default(T));
+ }
}
}
@@ -254,5 +254,24 @@ public void Does_Trailing_Backslashes()
Assert.That(deserialized.TestString, Is.EqualTo("Test")); // deserialized.TestString is NULL
}
+ [Test]
+ public void Deserialize_Correctly_When_Last_Item_Is_Null_in_array()
+ {
+ var arrayOfInt = new int?[2] {1, null };
+ var serialized = TypeSerializer.SerializeToString(arrayOfInt);
+ Console.WriteLine(serialized);
+ var deserialized = TypeSerializer.DeserializeFromString<int?[]>(serialized);
+ Assert.That(deserialized, Is.EqualTo(arrayOfInt));
+ }
+
+ [Test]
+ public void Deserialize_Correctly_When_Last_Item_Is_Null_in_list()
+ {
+ var arrayOfInt = new List<int?> { 1, null };
+ var serialized = TypeSerializer.SerializeToString(arrayOfInt);
+ Console.WriteLine(serialized);
+ var deserialized = TypeSerializer.DeserializeFromString<List<int?>>(serialized);
+ Assert.That(deserialized, Is.EqualTo(arrayOfInt));
+ }
}
}

0 comments on commit c52fd49

Please sign in to comment.