Add example for SolrDocument + Mapstruct
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức phù hợp với người mới
- 35/100
- Loại issue
- Tài liệu
- Độ rõ ràng
- Khá rõ ràng
- Mức độ hoạt động
- Đình trệ
- Công nghệ
- java
- Lĩnh vực
- documentation
Hướng nghiên cứu
Bắt đầu bằng cách xem xét các bố cục ví dụ Java hiện có trong repository, sau đó sử dụng ví dụ trong issue về SolrDocument, SolrResponseWrapper, ItemDTO và ItemMapper làm điểm khởi đầu. Thêm một ví dụ tập trung thể hiện việc mapping dựa trên wrapper và xác minh rằng ví dụ đó minh họa vấn đề iterable-to-non-iterable đã được báo cáo cùng cách giải quyết vấn đề.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
It would be nice to have an example that shows how to use SolrDocument with Mapstruct.
I was trying to use MapStruct with SolrDocument and couldn't find a comprehensive example that could guide me . I was facing below issue during compiling:
Can't generate mapping method from iterable type to non-iterable type.
Reason is SolrDocument implements Iterable interface and Target DTOs doesn't .
So i came up with below solution to deal with this.
Source Class
SolrDocument
Here SolrDocument internally has Map<String,Object> _fields;
Destination Class:
`public class ItemDTO {
private String id;
private String displayName;
private String availability;
private String price;
//getter
//setter
}
}`
Error : Can't generate mapping method from iterable type to non-iterable type.
Solution:
Created SolrResponseWrapper around SolrDocument like below:
`public class SolrResponseWrapper {
private SolrDocument document;
public SolrResponseWrapper(SolrDocument document) {
this.document = document;
}
public String get(String key) {
return this.document.get(key).toString();
}
}`
Now Mapper is defined below for SolResponseWrapper to ItemDTO.
`@Mapper
public interface ItemMapper {
ItemMapper INSTANCE = Mappers.getMapper(ItemMapper);
@Mappings({
@Mapping(expression = "java(record.get("product_id"))", target = "id"),
@Mapping(expression = "java(record.get("display_name"))", target = "displayName"),
@Mapping(expression = "java(record.get("availability"))", target = "availability"),
@Mapping(expression = "java(record.get("price"))", target = "price")
})
ItemDTO convertToItemDTO(SolrResponseWrapper record);
}`
If you think this is a good addition, please let me know. I will raise PR to have it included as an example.
- Ngôn ngữ chính
- Java
- Star
- 1.4k
- Fork
- 504
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Hướng dẫn đóng góp
Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của mapstruct/mapstruct-examples
-
Java 21 support Đang mở
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 35/100
mapstruct/mapstruct-examples#153 · 1 bình luận ·
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 25/100
mapstruct/mapstruct-examples#149 · 1 bình luận ·
-
mapstruct-protobuf3 use lombok:UnsupportedOperationException(Collections$UnmodifiableCollection) Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 45/100
mapstruct/mapstruct-examples#142 ·
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 15/100
mapstruct/mapstruct-examples#138 ·
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 25/100
mapstruct/mapstruct-examples#128 · 1 reaction ·
Tất cả issue của mapstruct/mapstruct-examples
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
elastic/gradle-plugins#157 ·
-
enhancement Tools
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 75/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
apache/rocketmq-dashboard#5008 ·
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
-
DETECT_PARAMETER_NAMES=false silently disables @ConstructorProperties-based Creator detection too Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
FasterXML/jackson-databind#6229 ·