I have a problem regarding the mapping of Mapstruct. Since I need to handle a huge amount of classes, I want to severly use automatic code generation and mapping.
My current issue is to map a xml class (viewmodel) to a Bo. The viewmodel ist automatically generated code from a xsd. Each class variable has a tag "XmlElement" which carries the name of a database table column. This string is also named in the Bo in the "Column" annotations. I want to make Mapstruct somehow connect each source with a target automatically according to the annotations. Performance is not an issue.
Can anybody give me a hint on how this is possible?
Thanks to all Oliver
BO:
@Entity
@Table(name = "table_y")
public class ClassY implements Identifiable<AVId> {
@Valid
@EmbeddedId
private AVId id;
@Column(name = "rg_m_id")
@Digits(integer = DataTypeSize.NUMBER_22, fraction = 0)
private Long mandantId;
@Column(name = "vp_m_id")
@Digits(integer = DataTypeSize.NUMBER_22, fraction = 0)
private Long vertragspartnerMandantId;
@Column(name = "ee_kurzbez")
@Size(max = DataTypeSize.VARCHAR_16)
private String eeKurzbezeichnung;
@Column(name = "vp_kurzbez")
@Size(max = DataTypeSize.VARCHAR_16)
private String vertragspartnerKurzbezeichnung;
@Column(name = "v_beschreibung")
@Size(max = DataTypeSize.VARCHAR_4000)
private String vBeschreibung;
//getter and setter
}
XML (ViewModel):
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "T_AV_Row", propOrder = {})
public class TXRow {
@XmlElement(name = "rg_m_id", required = true)
protected Long rgMId;
@XmlElement(name = "vp_m_id", required = true)
protected Long vpMId;
@XmlElement(name = "ee_kurzbez", required = true)
protected String eeKurzbez;
@XmlElement(name = "vp_kurzbez", required = true)
protected String vpKurzbez;
@XmlElement(name = "v_beschreibung", required = true)
protected String vBeschreibung;
//getter and setter
}
Mapstruct interface:
@Mapper()
public interface IXYMapper {
IXYMapper INSTANCE = Mappers.getMapper( IXYMapper.class );
ClassY xToy(TXRow tXRow);
}
Aucun commentaire:
Enregistrer un commentaire