MapperStruct maps null

I have the following entity and resource and mapper classes

I have an endpoint which queries with vehicleId,

and I am querying the record by vehivleId and returns a value but while mapping it maps null as like the following line

My pom definition is also correct, what should I change ?

mapstructMapper.chargeDetailEntityToResource(chargeDetailRecord)

package com.dcs.mcs.mapper;

@Mapper(componentModel = "spring")
public interface ChargeDetailRecordMapper {

    ChargeDetailEntity chargeDetailResourceToEntity(ChargeDetailRecordResource chargeDetailRecordResource);

    ChargeDetailRecordResource chargeDetailEntityToResource(ChargeDetailEntity chargeDetailEntity);

}

Entity class

@Entity
@Table(name = "charge_detail_records")
@Getter
@Setter
public class ChargeDetailEntity {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    @Column(name = "session_id", nullable = false, unique = true)
    private String sessionId;

    @Column(name = "vehicle_id", nullable = false)
    private String vehicleId;

    @Column(name = "total_cost", nullable = false)
    private BigDecimal totalCost;

    @Column(name = "start_time", nullable = false)
    private LocalDateTime startTime;

    @Column(name = "end_time", nullable = false)
    private LocalDateTime endTime;

    @Column(name = "created_at", nullable = false)
    @CreationTimestamp
    private LocalDateTime createdAt;

    @Column(name = "updated_at", nullable = false)
    @UpdateTimestamp
    private LocalDateTime updatedAt;

}

Resource class

@AllArgsConstructor
@NoArgsConstructor
@Getter
@Setter
@Builder
public class ChargeDetailRecordResource {

    private String sessionId;
    private String vehicleId;
    private LocalDateTime startTime;
    private LocalDateTime endTime;
    private BigDecimal totalCost;

}

But it maps null everything

How could I solve this ?

Thanks.

mapper class

Map struct maps everything null

How we could fix this ?

Leave a Comment