I am working in spring batch application. I need to get the list of elements from ItemWriter
object and set it each list into respective domain object and save it to Mongo DB. But when I am get trying to get a list from profile object from writer, it has all the data in required list. When I try to assign it to respective domain object, I am getting the error. I am not able to get any data from a list inside the profileDTO
.
I have tried with multiple ways of getting the list data and set it into respective domain objects. But each time when assigning it to domain class, it through exception that java.lang.ClassCastException: org.springframework.util.LinkedCaseInsensitiveMap
I have also gone through the link but i didn't get it. I am using spring version 5.1.2. Please help me to solve this issue. below is code snippet
ProfileDTO
which is having List ofDueDiligenceDTO
which is passed intoItemWriter
. Which hold both profileDTO as well as DueDiligenceDTO data. There is no NullPointers.@Data Builder @AllArgsConstructor @Document(value= "Profile") public class ProfileDTO { private long profileId; private LocalDateTime reviewDate; private int tierLevelNumber; private List<DueDiligenceDTO> dueDiligences; }
DueDiligenceDTO
@Data @NoArgsConstructor public class DueDiligenceDto{ private String categoryCode; }
And the writer class, I have:
public class ProfileWriter implements ItemWriter<ProfileDTO> { @Override public void write(List<? extends ProfileDTO> profile) throws Exception { riskProfile.stream().forEach(risk -> setProfile(risk)); } private void setProfile(ProfileDTO prop) { List<DueDiligence> DueDiligences = new ArrayList<>(); for(DueDiligenceDTO diligenceDetails : prop.getDueDiligences()) { List<DueDiligenceDetailDTO> dueDiligenceDtlList= diligenceDetails.getDueDiligenceDetails(); if(null!=dueDiligenceDtlList && !dueDiligenceDtlList.isEmpty()) { for(DueDiligenceDetailDTO detailDTO:dueDiligenceDtlList) { // then, need to set detailDTO into separate domain object and // set diligenceDetails into separate domain object. } } } } }
At
for(DueDiligenceDTO diligenceDetails : prop.getDueDiligences())
-->
Error stacktrace:java.lang.ClassCastException: org.springframework.util.LinkedCaseInsensitiveMap cannot be cast to com.data.profile.dto.DueDiligenceDetailDTO
Please help me how to get it resolved.