모델 개체를 dto 모델에 매핑하고 싶습니다. 개체 중 하나에 대한 매퍼가 이미 있습니다. 다른 클래스에 있는 다른 매퍼에서 이 매퍼를 어떻게 재사용할 수 있습니까?
나는 모델로 아래에있다
@Getter
@AllArgsConstructor
@ToString
public class History {
@JsonProperty("identifier")
private final Identifier identifier;
@JsonProperty("submitTime")
private final ZonedDateTime submitTime;
@JsonProperty("method")
private final String method;
@JsonProperty("reason")
private final String reason;
@JsonProperty("dataList")
private final List<Data> dataList;
}
@DynamoDBTable(tableName = "history")
@Data
@NoArgsConstructor
public class HistoryDynamo {
@DynamoDBRangeKey(attributeName = "submitTime")
@DynamoDBTypeConverted(converter = ZonedDateTimeType.Converter.class)
private ZonedDateTime submitTime;
@DynamoDBAttribute(attributeName = "identifier")
@NonNull
private Identifier identifier;
@DynamoDBAttribute(attributeName = "method")
private String method;
@DynamoDBAttribute(attributeName = "reason")
private String reason;
@DynamoDBAttribute(attributeName = "dataList")
private List<Data> dataList;
}
@Data
@DynamoDBDocument
@NoArgsConstructor
public class Identifier implements Serializable {
@DynamoDBAttribute(attributeName = "number")
private String number;
@DynamoDBAttribute(attributeName = "cityCode")
@NonNull
private String cityCode;
@DynamoDBAttribute(attributeName = "countryCode")
@NonNull
private String countryCode;
@DynamoDBTypeConverted(converter = LocalDateType.Converter.class)
private LocalDate mydate;
}
@Data
@EqualsAndHashCode
@NoArgsConstructor
@RequiredArgsConstructor
@JsonInclude(JsonInclude.Include.NON_NULL)
public class Identifier implements Serializable {
@NonNull
@lombok.NonNull
@NotNull
private String number;
@NonNull
@lombok.NonNull
@NotNull
private City city;
@NonNull
@lombok.NonNull
@NotNull
private Country country;
@JsonDeserialize(using = LocalDateDeserializer.class)
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'Z'")
@DateTimeFormat(pattern = "yyyy-MM-dd'Z'")
@NonNull
@lombok.NonNull
@NotNull
private LocalDate mydate;
}
그리고 여기 내 매핑이 있습니다
@Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.WARN, injectionStrategy = InjectionStrategy.CONSTRUCTOR, nullValueMappingStrategy = NullValueMappingStrategy.RETURN_NULL)
public interface IdentifierMapper {
IdentifierMapper MAPPER = Mappers.getMapper(IdentifierMapper.class);
@Mappings({@Mapping(source = "identifier.number", target = "number"),
@Mapping(source = "identifier.city.code", target = "cityCode"),
@Mapping(source = "identifier.country.code", target = "countryCode"),
@Mapping(source = "identifier.mydate", target = "mydate")})
@Named("toIdentifierDynamo")
myproject.entity.dynamo.Identifier toIdentifierDynamo(myproject.model.Identifier identifier);
}
@Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.WARN, injectionStrategy = InjectionStrategy.CONSTRUCTOR,
nullValueMappingStrategy = NullValueMappingStrategy.RETURN_NULL, uses = {IdentifierMapper.class})
public interface HistoryMapper {
HistoryMapper MAPPER = Mappers.getMapper(HistoryMapper.class);
@Mappings({@Mapping(source = "identifier", target = "identifier", qualifiedByName = "toIdentifierDynamo"),
@Mapping(source = "method", target = "method"),
@Mapping(source = "reason", target = "reason"),
@Mapping(source = "timestamp", target = "timestamp")})
HistoryDynamo toHistoryDynamo(History history);
}
History를 HistoryDynamo에 매핑하고 IdentifierMapper를 재사용하여 HistoryDynamo의 객체 중 하나를 매핑하고 싶습니다. toHistoryDynamo에서 toIdentifierDynamo를 어떻게 사용할 수 있습니까?