The JsonSerializer should add a method PopulateObject() where, besides the stream or string, it also accepts an existing object.
The method should read the json and only update the properties that are actually defined in the json and leave the other properties of the object intact. In other words: it should act as an "update" and not "replace".
Write the PopulateObject() model and cover this behavior with the unit tests.
Example model:
public class MyModel
{
public string FirstName { get; set; }
public string LastName { get; set; }
}
The json can contain:
Then this test should succeed:
var model = new MyModel
{
FirstName = "John",
LastName = "Doe1"
};
var serializer = jsonSerializerFactory.CreateSerializer();
serializer.PopulateObjectFromString(jsonString, model);
Assert.That(model.FirstName, Is.EqualTo("John"));
Assert.That(model.LastName, Is.EqualTo("Doe2"));
The JsonSerializer should add a method PopulateObject() where, besides the stream or string, it also accepts an existing object.
The method should read the json and only update the properties that are actually defined in the json and leave the other properties of the object intact. In other words: it should act as an "update" and not "replace".
Write the
PopulateObject()model and cover this behavior with the unit tests.Example model:
The json can contain:
Then this test should succeed: