How to populate a collection from a Map?

12 views
Skip to first unread message

Andras Soltesz

unread,
Sep 18, 2017, 11:45:34 AM9/18/17
to Dozer Mapper
Hi All,

I am new to Dozer and haven't found info on this one:

I would like to populate an embedded collection from http request parameters with Dozer.

The request parameters  are available for me as a java.util.Map (as 'requestMap" below) and the entries look like this:

Map<String, String> requestMap (key -> value) =
- "id" -> "15"
- "title" -> "Nice article about electric cars"
- "comments[0].text" -> "comment 1"
- "comments[1].text" -> "comment 2"

The beans I would like to populate:

public class Article {
  int id;
  String title;
  List<Comment> comments;
}

public class Comment {
  String text;
}


When I use "mapper.map(requestMap, article)", the article "title" and the "id" attributes get populated from the map nicely. However, the "comments" collection does not get populated.

Is Dozer supposed to be able to populate the collection as well? What do I have to do to get it populated?

Gareth Healy

unread,
Feb 24, 2018, 8:58:53 AM2/24/18
to Dozer Mapper
You'd need to use a custom converter, to map the key of a comment to an actual instance.
Reply all
Reply to author
Forward
0 new messages