The mapstruct not working if I make Vo object field and POJO objects field as private.
POJO Class:
@Getter
@Setter
@Entity
@Table(name = "items")
public class MtampItem extends AbstractEntity implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "item_id")
private Long itemId;
@Column(name = "item_name", nullable = false)
private String itemName;
@Column(name = "item_quantity", nullable = false)
private Integer itemQuantity;
@Column(name = "item_packed_on", nullable = false)
private String itemPackedOn;
@OneToOne(mappedBy = "items")
private MtampPrice price;
@ManyToOne
@JoinColumn(name = "store_id", nullable = false)
private MtampStores stores;
}
@Getter
@Setter
@Entity
@Table(name = "price")
public class MtampPrice extends AbstractEntity implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "price_id")
private Long priceId;
@Column(name = "total_price")
private Integer totalPrice;
@Column(name = "currency")
private String currency;
@OneToOne(cascade = CascadeType.ALL)
@JoinColumn(name = "itemId", referencedColumnName = "item_id")
private MtampItem items;
}
@Entity
@Getter
@Setter
@Table(name = "stores")
public class MtampStores extends AbstractEntity implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "store_id")
private Long storeId;
@Column(name = "store_name")
private String storeName;
@Column(name = "store_address_1")
private String storeAddress1;
@Column(name = "store_address_2")
private String storeAddress2;
@Column(name = "store_location")
private String storeLocation;
@Column(name = "city")
private String city;
@Column(name = "zip_code")
private String zipcode;
@OneToMany(mappedBy = "stores", cascade = CascadeType.ALL)
private List<MtampItem> items;
}
VO Object:
@Getter
@Setter
public class Stores implements Serializable {
private static final long serialVersionUID = -9072061519155322550L;
@JsonProperty("store_id")
private Integer storeId;
@JsonProperty("store_name")
private String storeName;
@JsonProperty("store_address1")
private String storeAddress1;
@JsonProperty("store_address2")
private String storeAddress2;
@JsonProperty("store_location")
private String storeLocation;
@JsonProperty("city")
private String city;
@JsonProperty("zipcode")
private String zipcode;
@JsonProperty("items")
private List<Item> items = null;
@JsonProperty("created_by")
private String createdBy;
@JsonProperty("created_on")
private String createdOn;
@JsonProperty("last_modified_by")
private String lastModifiedBy;
@JsonProperty("last_modified_on")
private String lastModifiedOn;
}
@Getter
@Setter
public class Price implements Serializable {
private static final long serialVersionUID = -3893171253167040027L;
@JsonProperty("price_id")
private Integer priceId;
@JsonProperty("total_price")
private Integer totalPrice;
@JsonProperty("currency")
private String currency;
}
@Getter
@Setter
public class Item implements Serializable {
private static final long serialVersionUID = -1712026895026221162L;
@JsonProperty("item_id")
private Integer itemId;
@JsonProperty("item_name")
private String itemName;
@JsonProperty("item_quantity")
private Integer itemQuantity;
@JsonProperty("item_packed_on")
private String itemPackedOn;
@JsonProperty("price")
private Price price;
}
Mapper interface:
@Mapper(componentModel = "spring")
public interface StoreMapper {
MtampStores mapStoreToEntityStores(Stores stores);
Stores mapEntityStoresToStores(MtampStores stores);
}
When I try to build we are getting the below generated code.
@Component
public class StoreMapperImpl implements StoreMapper {
@Override
public MtampStores mapStoreToEntityStores(Stores stores) {
if ( stores == null ) {
return null;
}
MtampStores mtampStores = new MtampStores();
return mtampStores;
}
@Override
public Stores mapEntityStoresToStores(MtampStores stores) {
if ( stores == null ) {
return null;
}
Stores stores1 = new Stores();
return stores1;
}
}
Issue: When I make the field of VO and POJO class fields as private the generated code not considering the fields for mapping. Can I know where I am making mistake.