Skip to content

Implement PopulateObject for IJsonSerializer#67

Merged
GeertvanHorrik merged 2 commits into
developfrom
copilot/implement-populateobject-extensions
May 30, 2026
Merged

Implement PopulateObject for IJsonSerializer#67
GeertvanHorrik merged 2 commits into
developfrom
copilot/implement-populateobject-extensions

Conversation

Copilot AI commented May 30, 2026

Copy link
Copy Markdown
Contributor

IJsonSerializer had no way to partially update an existing object from JSON — only full deserialization (replace) was available.

Changes

  • IJsonSerializer — adds void PopulateObject(Stream stream, object target)
  • JsonSerializer — implements it via JsonDocument + reflection: iterates JSON properties, resolves matching CLR properties case-insensitively, and deserializes each value using the serializer's configured JsonSerializerOptions; unmatched properties on the target are left untouched
  • IJsonSerializerExtensions — adds PopulateObject<T>(Stream, T) and PopulateObjectFromString<T>(string, T) convenience overloads
  • Public API snapshot — updated to reflect new members

Usage

var model = new MyModel { FirstName = "John", LastName = "Doe1" };

serializer.PopulateObjectFromString("""{ "lastName": "Doe2" }""", model);

// model.FirstName == "John"   (untouched)
// model.LastName  == "Doe2"   (updated)

@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

Copilot AI changed the title [WIP] Add PopulateObject extensions method for JsonSerializer Implement PopulateObject for IJsonSerializer May 30, 2026
Copilot AI requested a review from GeertvanHorrik May 30, 2026 09:05
public void Updates_Only_Properties_Present_In_Json()
{
var serializer = CreateSerializer();
var model = new SampleModel { Name = "John", Value = 10, Status = Status.Active };

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot object initializers should be separated on new lines for readability

@GeertvanHorrik GeertvanHorrik marked this pull request as ready for review May 30, 2026 09:12
@GeertvanHorrik GeertvanHorrik merged commit 2465cb8 into develop May 30, 2026
1 check was pending
@GeertvanHorrik GeertvanHorrik deleted the copilot/implement-populateobject-extensions branch May 30, 2026 09:12
Copilot stopped work on behalf of GeertvanHorrik due to an error May 30, 2026 09:12
Copilot AI requested a review from GeertvanHorrik May 30, 2026 09:12
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

Successfully merging this pull request may close these issues.

Implement PopulateObject extensions method for JsonSerializer

3 participants