是否可以使用MapStruct将java中的HashMap转换为List?
我们正试图找到一种使用mapstruct将HashMap转换为List的方法,但在internet上没有这样的帮助。有人知道使用mapstruct的方法吗 我们已经尝试过定义抽象类和使用抽象映射,但没有任何效果是否可以使用MapStruct将java中的HashMap转换为List?,java,mapstruct,Java,Mapstruct,我们正试图找到一种使用mapstruct将HashMap转换为List的方法,但在internet上没有这样的帮助。有人知道使用mapstruct的方法吗 我们已经尝试过定义抽象类和使用抽象映射,但没有任何效果 @Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.WARN, implementationPackage = "com.mapstruct.mapper.impl") public abst
@Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.WARN,
implementationPackage = "com.mapstruct.mapper.impl")
public abstract class OrderLineMapper {
public com.internal.epfo.v1.OrderLine toOrderLineList(Map.Entry<Integer, OrderLine> orderLineEntry) {
com.internal.epfo.v1.OrderLine orderLine = new com.internal.epfo.v1.OrderLine();
orderLine.setCategoryTypeCode(orderLineEntry.getValue().getCategoryTypeCode());
orderLine.getProducts().addAll(getProductInfoList(orderLineEntry.getValue().getProducts()));
return orderLine;
}
List<com.internal.epfo.v1.ProductInfo> getProductInfoList(EnrichProductInfoMap<String, ProductInfo> products) {
List<com.internal.epfo.v1.ProductInfo> productInfo = products.values().stream().collect(Collectors.toCollection( ArrayList<com.internal.epfo.v1.ProductInfo>::new ));
return productInfo;
}
@MapMapping
public abstract List<com.internal.epfo.v1.OrderLine> toOrderLineList(
Map<Integer, OrderLine> orderLine);
}
@Mapper(componentModel=“spring”,unappedTargetPolicy=ReportingPolicy.WARN,
implementationPackage=“com.mapstruct.mapper.impl”)
公共抽象类OrderLineMapper{
public com.internal.epfo.v1.OrderLine到orderlinelist(Map.Entry orderLineEntry){
com.internal.epfo.v1.OrderLine OrderLine=新建com.internal.epfo.v1.OrderLine();
orderLine.setCategoryTypeCode(orderLineEntry.getValue().getCategoryTypeCode());
orderLine.getProducts().addAll(getProductInfoList(orderLineEntry.getValue().getProducts());
退货订单行;
}
列表getProductInfoList(EnrichProductInfoMap产品){
List productInfo=products.values().stream().collect(Collectors.toCollection(ArrayList::new));
返回productInfo;
}
@地图制图
公共摘要列表到OrderLineList(
地图订购线);
}
无法生成从非iterable类型到iterable类型的映射方法。没有现成的支持将
映射
转换为列表
。但是,您可以添加自定义方法
public abstract class OrderLineMapper {
public OrderLineV1 toOrderLine(Map.Entry<Integer, OrderLine> orderLineEntry) {
OrderLineV1 orderLine = new OrderLineV1();
orderLine.setCategoryTypeCode(orderLineEntry.getValue().getCategoryTypeCode());
orderLine.getProducts().addAll(getProductInfoList(orderLineEntry.getValue().getProducts()));
return orderLine;
}
List<ProductInfoV1> getProductInfoList(EnrichProductInfoMap<String, ProductInfo> products) {
List<ProductInfoV1> productInfo = products.values().stream().collect(Collectors.toCollection( ArrayList<ProductInfoV1>::new ));
return productInfo;
}
public List<OrderLineV1> toOrderLineList(Map<Integer, OrderLine> orderLine) {
return orderLine == null ? null : toOrderLineList(orderLine.entrySet());
}
public abstract List<OrderLineV1> toOrderLineList(Collection<Map.Entry<Integer, OrderLine> orderLineCollection);
}
公共抽象类OrderLineMapper{
public OrderLineV1到orderline(Map.Entry orderLineEntry){
OrderLineV1 orderLine=new OrderLineV1();
orderLine.setCategoryTypeCode(orderLineEntry.getValue().getCategoryTypeCode());
orderLine.getProducts().addAll(getProductInfoList(orderLineEntry.getValue().getProducts());
退货订单行;
}
列表getProductInfoList(EnrichProductInfoMap产品){
List productInfo=products.values().stream().collect(Collectors.toCollection(ArrayList::new));
返回productInfo;
}
公共列表到订单行列表(映射订单行){
return orderLine==null?null:toOrderLineList(orderLine.entrySet());
}
public abstract List to orderlinelist(Collection对于将Map
转换为List
没有现成的支持。但是,您可以添加自定义方法
public abstract class OrderLineMapper {
public OrderLineV1 toOrderLine(Map.Entry<Integer, OrderLine> orderLineEntry) {
OrderLineV1 orderLine = new OrderLineV1();
orderLine.setCategoryTypeCode(orderLineEntry.getValue().getCategoryTypeCode());
orderLine.getProducts().addAll(getProductInfoList(orderLineEntry.getValue().getProducts()));
return orderLine;
}
List<ProductInfoV1> getProductInfoList(EnrichProductInfoMap<String, ProductInfo> products) {
List<ProductInfoV1> productInfo = products.values().stream().collect(Collectors.toCollection( ArrayList<ProductInfoV1>::new ));
return productInfo;
}
public List<OrderLineV1> toOrderLineList(Map<Integer, OrderLine> orderLine) {
return orderLine == null ? null : toOrderLineList(orderLine.entrySet());
}
public abstract List<OrderLineV1> toOrderLineList(Collection<Map.Entry<Integer, OrderLine> orderLineCollection);
}
公共抽象类OrderLineMapper{
public OrderLineV1到orderline(Map.Entry orderLineEntry){
OrderLineV1 orderLine=new OrderLineV1();
orderLine.setCategoryTypeCode(orderLineEntry.getValue().getCategoryTypeCode());
orderLine.getProducts().addAll(getProductInfoList(orderLineEntry.getValue().getProducts());
退货订单行;
}
列表getProductInfoList(EnrichProductInfoMap产品){
List productInfo=products.values().stream().collect(Collectors.toCollection(ArrayList::new));
返回productInfo;
}
公共列表到订单行列表(映射订单行){
return orderLine==null?null:toOrderLineList(orderLine.entrySet());
}
公共摘要列表到OrderLineList(不相关):考虑导入类型,而不是使用完全合格的类型在整个过程中产生如此令人难以置信的线噪声。这只会使代码比需要读10倍。这可能是一个重复的问题。请参阅:无关:考虑导入您的类型,而不是拥有如此令人难以置信的线噪声B。y到处都在使用完全限定类型。仅此一点,您的代码就比需要的难读10倍。这可能是一个重复的问题。请参阅: