Skip to content

Implement PopulateObject extensions method for JsonSerializer #66

Description

@GeertvanHorrik

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:

{
    "lastName": "Doe2"
}

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"));

Metadata

Metadata

Labels

No labels
No labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions