Skip to content
This repository was archived by the owner on Dec 24, 2022. It is now read-only.

Commit ffca4e1

Browse files
committed
fixed #304
fixed broken tests related to ModelWithAllTypes.cs
1 parent 5662609 commit ffca4e1

File tree

4 files changed

+23
-5
lines changed

4 files changed

+23
-5
lines changed

src/ServiceStack.Text/Common/DeserializeListWithElements.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,13 +166,16 @@ public static ICollection<T> ParseGenericList(string value, Type createListType,
166166
}
167167
}
168168

169-
if (Serializer.EatItemSeperatorOrMapEndChar(value, ref i)
170-
&& i == valueLength)
169+
if (Serializer.EatItemSeperatorOrMapEndChar(value, ref i) && i == valueLength)
171170
{
172171
// If we ate a separator and we are at the end of the value,
173172
// it means the last element is empty => add default
174173
to.Add(default(T));
174+
continue;
175175
}
176+
177+
if (listValue == null)
178+
to.Add(default(T));
176179
}
177180

178181
}

tests/ServiceStack.Text.Tests/DynamicModels/ModelWithAllTypes.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public static ModelWithAllTypes Create(byte i)
5050
ByteValue = i,
5151
CharValue = (char)i,
5252
CustomException = new CustomException("CustomException " + i),
53-
DateTimeValue = new DateTime(i),
53+
DateTimeValue = new DateTime(2000, 1, 1 + i),
5454
DecimalValue = i,
5555
DoubleValue = i,
5656
Exception = new Exception("Exception " + i),

tests/ServiceStack.Text.Tests/JsonTests/BasicJsonTests.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,21 @@ public void Can_parse_json_with_nullable_valuetypes_that_has_no_value_specified(
121121
Assert.That(item.DateTime, Is.Null, "datetime");
122122
}
123123

124+
[Test]
125+
public void Can_parse_mixed_list_nulls()
126+
{
127+
Assert.That(JsonSerializer.DeserializeFromString<List<string>>("[\"abc\",null,\"cde\",null]"),
128+
Is.EqualTo(new string[] { "abc", null, "cde", null }));
129+
}
130+
131+
[Test]
132+
public void Can_parse_mixed_enumarable_nulls()
133+
{
134+
Assert.That(JsonSerializer.DeserializeFromString<IEnumerable<string>>("[\"abc\",null,\"cde\",null]"),
135+
Is.EqualTo(new string[] { "abc", null, "cde", null }));
136+
}
137+
138+
124139
[Test]
125140
public void Can_handle_json_primitives()
126141
{

tests/ServiceStack.Text.Tests/JsonTests/JsonArrayObjectTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,13 @@ public void Can_parse_empty_array_with_tab()
2929
[Test]
3030
public void Can_parse_array_with_null()
3131
{
32-
Assert.That(JsonArrayObjects.Parse("[null]"), Is.Empty);
32+
Assert.That(JsonArrayObjects.Parse("[null]"), Is.EqualTo(new string[]{null}));
3333
}
3434

3535
[Test]
3636
public void Can_parse_array_with_nulls()
3737
{
38-
Assert.That(JsonArrayObjects.Parse("[null,null]"), Is.Empty);
38+
Assert.That(JsonArrayObjects.Parse("[null,null]"), Is.EqualTo(new string[]{null, null}));
3939
}
4040

4141
[Test]

0 commit comments

Comments
 (0)