GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Support Iterable interface as an input · Issue #3376 · mapstruct/mapstruct

Support Iterable interface as an input #3376

New issue
Copy link
New issue
Copy link
Closed
Closed
Support Iterable interface as an input#3376
Copy link
Labels
enhancement
Milestone
1.6.0.Beta1

Description

@SergeS
SergeS
opened on Sep 8, 2023
Issue body actions

Use case

We are using records with collections defined as Iterable<T> , and it would be handy to somehow make mapstruct able to convert from Iterable<T> to any other Iterable type. For example.

record B (
  String value;
) {}

record A (
  Iterable<B> listOfB
) {}

class C {
  List<String> listOfB
}

@Mapper
interface Mapper {
  C mapAtoC(A input);

  default String mapBToSting(B in) {
    return in.value();
  }
}

Generated Code

interface MapperImpl {
  public C mapAtoC(A input) {
    ....

    C c = new C();
    
    List<String> listOfB = StreamSupport.stream(labels.spliterator(), false).map(this::mapBToSting).toList();
    c.setListOfB(listOfB);

    ....
  }
}

Possible workarounds

Currently I need to create such functions manually

MapStruct Version

1.5.5.Final

Activity

  1. filiphr commented on Sep 16, 2023

    @filiphr
    filiphr
    on Sep 16, 2023
    Member
    More actions

    This is a valid request. We might need to change the map part a bit, but apart from that I don't see why not add such a functionality. I'll leave this is a future enhancement so we can decide how to add it after 1.6. However, if you are interested in contributing, we are more than happy to look at a PR.

  2. filiphr
    added
    enhancement
    on Sep 16, 2023
  3. filiphr
    added this to the 1.7.0 milestone on Sep 16, 2023
  4. kooixh commented on Oct 25, 2023

    @kooixh
    kooixh
    on Oct 25, 2023
    Contributor
    More actions

    I've taken a stab at this, really appreciate if anyone can review my PR

  5. thunderhook
    added a commit that references this issue on Oct 31, 2023

    #3376 support mapping from iterables to collection

    5d39314
  6. thunderhook
    closed this as completedon Oct 31, 2023
  7. filiphr
    modified the milestones: 1.7.0, 1.6.0 on Nov 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      • 1.6.0.Beta1

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402503 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.