-
Notifications
You must be signed in to change notification settings - Fork 359
Polymorphic mapping with collections maps only base class properties #793
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
@neistow Yes, it is related. |
For now I resorted to adding config explicitly, but I think replacing |
If using .Include() makes it work, then I think that will also be easy to fix. |
But this will most likely be a separate setting |
Introducing options like Changing the current behavior of regular non-collection mapping may break existing production codebases. As a library user, I expect the library to handle such kind of mapping by default. It took me some time to figure out that the problem was in |
Look, in your case you get exactly what you asked for. Collection This is itself a Generic type
This Mapster analyzes types, not the runtime state of variables in the general case. |
This is the main problem ))
These will be special options that will need to be activated when really needed.
If you convert to json using JsonNet You will find that you get a json representation of the collection of items of type Base. This option should work too. |
@neistow In your case, do all the derived of the Base class exist in the same assembly as the Base class? |
Yes, they are all in the same assembly |
Hi, I'm trying a similar thing... I do have this issue but my intention is to have a collection of Base object with instances of each specific type... here I have an example with an old project but using Autompper instead
and my generic method returns a collection of Translating this to Mapster it would be something like:
Using Mapster I always get a collection of FieldDtos, always base clase... The issue happens regardless the mapping approach
|
@icalderazzo You can specify the Maybe you made a mistake, this config shouldn't work at all
Or you should map Using the original example it definitely works.
|
This might be related to #776. I have a class hierarchy and a base class DTO that combines all possible properties. When mapping a single item cast to the base class - derived properties are mapped, however, when mapping a collection of the base class items - derived properties are ignored. This doesn't seem like a consistent behavior to me and now it must be fixed with explicit map config.
The text was updated successfully, but these errors were encountered: