on 09-21-2017 9:31 AM
Hi Experts,
I have Map to be converted from Model object to Data Object. Map contains userModel as key , and list of users Wishlist(Wishlist2Model)
Now I want to write populator to convert the map of these model object to Data.
As of now, I know how to write populator of list of model object. but now it is for map of model
Any suggestions
Thanks in advance
Hello
Just curious as to why you have a Map of <User, Wishlist>
. There is a One-To-Many relation between User and Wishlist that can be used to find the wishlist for a user.
The right way depends on your use case exactly but in general, assuming you have this map type defined, and let's say you are referring to it in an entity called Container
, you would basically create a populator called ContainerUserWishlistMapPopulator
where your source and target would be something like ContainerModel
and ContainerData
.
Your populate method should look something like this -
public void populate(SOURCE source, TARGET target)throws ConversionException {
ServicesUtil.validateParameterNotNullStandardMessage("source", source);
ServicesUtil.validateParameterNotNullStandardMessage("target", target);
if (MapUtils.isEmpty(source.getUserWishlistMap())) {
target.setUserWishlistMap(Collections.emptyMap());
}
target.setUserWishlistMap(source.getUserWishlistMap().entrySet()
.stream()
.collect(Collectors.toMap(
entry -> getUserConverter().convert(entry.getKey()),
entry -> getWishlistConverter().convert(entry.getValue())
)));
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Ansari,
I feel you should iterate through the map.
First get the key, convert it to data . Now, get the value for that key ,call the coverters,covertALL(listvalue) .
Create new map and place your data in that.
Regards, Sid
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
8 | |
1 | |
1 | |
1 | |
1 | |
1 | |
1 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.