[英]DozerMapper maps by default, Set to HashSet which destroys the ordering of elements
我有2个DTOS,即OutputResponse和OutputDTO。 该类的格式如下:
class OutputDTO{
private LinkedHashSet<String> items;
}
class OutputResponse{
private Set<String> items;
}
当我尝试使用DozerMapper映射这2个对象时,它将目标映射到HashSet而不是LinkedHashSet。
class X{
DozerBeanMapper mapper;
mapper.map(OutputDTO.class, OutputResponse.class);
}
在上述情况下,map()方法将LinkedHashSet映射到HashSet,这会破坏输出响应的顺序。 有什么建议吗?
如果希望OutputResponse中的项目集具有某种顺序,则将需要使用其他Collection实现。 根据定义,集合是无序的。 列表是有序的,LinkedHashSet也是如此。 通过将项目定义为Set,您可以定义没有特定的顺序,并且Dozer通过使用HashSet兑现了该规范,该哈希也是无序的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.