Skip to content
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

[Question] Map several source field to single destination object #68

Open
petromir opened this issue May 14, 2017 · 5 comments
Open

[Question] Map several source field to single destination object #68

petromir opened this issue May 14, 2017 · 5 comments

Comments

@petromir
Copy link

Hi,

I read about similar case here https://github.com/jmapper-framework/jmapper-core/wiki/Flatten-And-Encapsulate, but I couldn't match it to my case. So here it is:

public class Dto {
   private String data;
   private String text;
   private List<Long> ids;
}

public class Entity {
   private List<NestedEntity> nestedEntities;
}

public class NestedEntity {
   private String data;
   private String text;
   private Long id;
}

Dto dto = new Dto();
dto.setData("data");
dto.setText("text");
List<Long> ids = new ArrayList<>();
ids.add(1);
ids.add(2);
dto.setIds(ids);

Entity entity = // JMapper getDestination method
entity.getNestedEntities().forEach(System.out::println)
// NestedEntity(data=data, text=text, id=1)
// NestedEntity(data=data, text=text, id=2)

What annotation should be placed in the Dtoin order to have a list of NestedEntity objects, which have same data located in data and text fields and different id taken from each item in ids

@avurro
Copy link
Member

avurro commented May 16, 2017

Hi @petromir,
There is currently no automation, default values are on the roadmap, meanwhile the only option is to use a static method only to encapsulate the mapping.

@petromir
Copy link
Author

@avurro Could you please provide an example?

@avurro
Copy link
Member

avurro commented May 22, 2017

Hi @petromir,
Actually looking better there is no way to encapsulate the mapping, but you gave me a good idea, that is to add a new placeholder that allows access to the root of the field, something like that: ${source.root} and ${destination.root} would be useful.
What do you think about it ?

@petromir
Copy link
Author

Hi @avurro,
Whatever you think will help us. Just provide few examples and probably a wiki article.

@netmikey
Copy link

I ran across a similar situation where I wanted to map two fields firstName and lastName onto one destination field fullName. I've been looking at global mappings and converters but nothing seems to fit the bill.

I'd like to do something like:

<!-- This is not working of course -->
<attribute name="fullName">
  <value>return ${source.root.firstName} + " " + ${source.root.lastName};</value>
</attribute>

Would that head into the same direction?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants