Mapster
Mapster copied to clipboard
Unable to reverse map from Destination.NestedObject.StringProperty to Source.StringProperty
I have a similar map config as below and I am trying to do a reverse map. However I get an Invalid Cast Exception when I add the map for string property on source to string property on destination's nested object. A different nested object has an integer property but this value can be mapped and reverse mapped to the destination's string property without issues
TypeAdapterConfig<Source, Destination>
.NewConfig()
.TwoWays()
.Map(dest => dest.StringProperty, src => src.NestedObject.IntProperty) // this works, but why?
.Map(dest => dest.StringProperty, src => src.DifferentNestedObject.StringProperty) // Invalid cast when reverse mapping
.PreserveReference(true);
// reverse mapping
Source? sourceObject = destObject.Adapt<Destination, Source>();
I get the following error
'Invalid cast from 'System.String' to 'ModelMap.Models.NestedClass'
@andrerav this issue still exists