0

I am new to java programming trying to do dto mapping,to implement data filtering

@Data
@FieldDefaults(makeFinal = true, level = AccessLevel.PRIVATE)
public class Request {
    List<EventType> eventType;
    String eventRef;
    List<Status> status;
    LocalDate DateFrom;
    LocalDate DateTo;
}

public class FilterDto   {

  @JsonProperty("eventType")
  @Valid
  private List<EventTypeEnum> eventType = null;

  @JsonProperty("eventRef")
  private String eventRef;

  @JsonProperty("status")
  @Valid
  private List<StatusEnum> status = null;

  @JsonProperty("DateFrom")
  @DateTimeFormat(iso = DateTimeFormat.ISO.DATE)
  private LocalDate DateFrom;

  @JsonProperty("DateTo")
  @DateTimeFormat(iso = DateTimeFormat.ISO.DATE)
  private LocalDate DateTo;

map struct func

Request map(List<FilterDto> filter);

I call this mapper in the controller

Request request = registryMapper.map(regPageReqDto.getFilter());

regPageReqDto generated class in swagger, which contains FilterDto

  • Are you sure you need to map a list of FilterDto into one single Request object? For me it looks more like you have to map each FilterDto to a separate Request object. If you have more than one FilterDto, you can use @IterableMapping to map a list of FilterDto into a list of Request. – Paul Marcelin Bejan Aug 07 '22 at 15:36
  • @PaulMarcelinBejan Yes, I need to filter each object with each other, thx for answer, I will try to use your advice – Marzepanio Tortus Aug 07 '22 at 15:43
  • So, if I understand it well, you can look at this answer : https://stackoverflow.com/a/73247962/13115701 – Paul Marcelin Bejan Aug 07 '22 at 16:00

0 Answers0