Coder Social home page Coder Social logo

Mapping to readonly array about mapperly HOT 7 CLOSED

heggi avatar heggi commented on June 5, 2024
Mapping to readonly array

from mapperly.

Comments (7)

github-actions avatar github-actions commented on June 5, 2024 1

πŸŽ‰ This issue has been resolved in version 2.7.0-next.2 πŸŽ‰

The release is available on:

Your semantic-release bot πŸ“¦πŸš€

from mapperly.

latonz avatar latonz commented on June 5, 2024

Thank you for this report. This is definitely something which needs improvement.

from mapperly.

jamescarterbellMSFT avatar jamescarterbellMSFT commented on June 5, 2024

I was trying to find a stop gap solution for this same exact problem (also doing gRPC mappings) and found the following generate code that seems right, but sadly the parent generator doesn't seem to find the void mapping methods:
private partial void MapToFooBars(List<FooBarModel>? source, RepeatedField<FooBarMessage> target)

Generates:

if (source == null)
    return;
target.Capacity = source.Capacity;
target.this[] = MapToFooBar(source.this[]);

from mapperly.

Blackclaws avatar Blackclaws commented on June 5, 2024

Its similar for dictionaries in generated grpc code. Those are MapFields which also only have a getter. Basically you have to copy the contents from one to the other.

There is a convenience method for this on the MapField however: .Add(IDictionary<string, string>) so in this case I'd expect that the mapper calls this. Is there any way to tell the mapper to deal with a certain field by providing a void method that takes the mapped and to map object?

from mapperly.

jamescarterbellMSFT avatar jamescarterbellMSFT commented on June 5, 2024

Hoping to open a PR for this asap, but it looks like right now mapperly won't map any readonly properties, but I think it would be fairly safe to default to a model of mapping readonly properties for reference types via existing ref mappers (map(source, target)) and leave open the possibility of doing the same for value types in the future via (map(source, ref target)), which means we may as well do both types using ref. Trying my hand at it to see how complex this is.

from mapperly.

latonz avatar latonz commented on June 5, 2024

Mapperly currently only supports object to object mappings in void mapping methods (thats why the implementation for private partial void MapToFooBars(List<FooBarModel>? source, RepeatedField<FooBarMessage> target) is generated as it is. For such cases the diagnostics should definitely be improved and indexed properties should not be mapped.). Mapperly only generates an implementation for void mapping methods, but does not consider them when looking for / generating a mapping for one type to another.
The main problem here is that Mapperly maps to a property by calling the setter of a property and therefore only takes target properties with an accessible setter into account. As described by @heggi, for collection properties this needs to be adjusted to map to read only collection properties by calling Add/AddRange. Would be very happy to accept any PR implementing this.

from mapperly.

github-actions avatar github-actions commented on June 5, 2024

πŸŽ‰ This issue has been resolved in version 2.7.0 πŸŽ‰

The release is available on:

Your semantic-release bot πŸ“¦πŸš€

from mapperly.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.