Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

Add example for SolrDocument + Mapstruct

Đang mở
#68 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

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

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. 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.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của mapstruct/mapstruct-examples

Tất cả issue của mapstruct/mapstruct-examples

Issue tương tự

Thêm issue về Java

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.