Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

Add example for SolrDocument + Mapstruct

オープン
#68 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
35/100
issue の種類
ドキュメント
明瞭さ
おおむね明確
活発さ
停滞
技術スタック
java
領域
documentation

調査の方向性

まず、リポジトリ内の既存の Java サンプルレイアウトを確認し、次に issue にある SolrDocument、SolrResponseWrapper、ItemDTO、ItemMapper の例を出発点として使用します。wrapper ベースのマッピングを示す、焦点を絞った例を追加し、その例が報告された iterable-to-non-iterable の問題とその解決策を実証していることを確認します。

索引モデルが issue の本文から書いたものです。

説明

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.

主要言語
Java
スター
1.4k
フォーク
504
PR マージ指標
30日以内にマージされた PR はありません

コントリビューションガイド

このリポジトリのコントリビューションガイドは索引されていません

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

mapstruct/mapstruct-examples のほかの issue

mapstruct/mapstruct-examples の issue をすべて見る

似ている issue

Java の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。