agileobjects / AgileMapper

A zero-configuration, highly-configurable, unopinionated object mapper with viewable execution plans. Flattens, unflattens, deep clones, merges, updates and projects queries. .NET 3.5+ and .NET Standard 1.0+.
MIT License
460 stars 27 forks source link

Unable to map class if property has JsonDocument class #210

Closed NanFengCheong closed 3 years ago

NanFengCheong commented 3 years ago

https://dotnetfiddle.net/vAa1An

SteveWilkes commented 3 years ago

Hi,

Might this be the same situation as issue #191 ?

Steve

SteveWilkes commented 3 years ago

Actually, sorry - I think it's just a configuration issue.

Instead of:

Mapper.WhenMapping
    .From<JsonDocument>()
    .ToANew<JsonDocument>()
    .CreateInstancesUsing(ctx => JsonDocument.Parse(ctx.Source.RootElement.GetRawText(), default));

Use:

Mapper.WhenMapping
    .From<JsonDocument>()
    .To<JsonDocument>()
    .CreateInstancesUsing(ctx => JsonDocument.Parse(ctx.Source.RootElement.GetRawText(), default));

Using ToANew<T>() applies the configuration only to new object mappings, not to updates as you're doing in your fiddle.

Hope that helps,

Steve

NanFengCheong commented 3 years ago

Seems working now. Thanks