Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deserialization reuses default List instead of creating new one #59

Open
Slimior opened this issue Jul 7, 2018 · 0 comments
Open

Deserialization reuses default List instead of creating new one #59

Slimior opened this issue Jul 7, 2018 · 0 comments

Comments

@Slimior
Copy link

Slimior commented Jul 7, 2018

If a class i want to (de)serialize has an IEnumerable<T> property with default value set to some List, after deserialization, such property will have both items set by default and deserialized.

using a type TestClass:

class TestClass 
{
    IEnumerable<string> SomeSequence {get; set;} = new List<string>{"test"};
}

the following fails

[Test]
public void TestSerializeDeserialize()
{
	var serializer = new Serializer();
	var value = new TestClass();
	var serialized = serializer.Deserialize<TestClass>(serializer.Serialize(value));
	Assert.That(serialized, Is.EqualTo(value));
}

as serialized.SomeSequence is now equal to new List<string>{"test", "test"}.

However, if the default value is set to an array (new string[]) this does not occur.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant