-2

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

  1. ProfileDTO which is having List of DueDiligenceDTO which is passed into ItemWriter. 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;            
    }
    
  2. 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.

Ömer Erden
  • 7,680
  • 5
  • 36
  • 45
escort
  • 147
  • 1
  • 1
  • 10

1 Answers1

0

As per the error message you are trying to asign object of LinkedCaseInsensitiveMap to a variable of DueDiligenceDetailDTO
share the complete error log and code, so that i can tell you where exactly you need to modify.

TheSprinter
  • 1,523
  • 17
  • 30
  • I am trying to get ItemWriter's profileDTO data which holds a list of DueDiligence and need to set it to separate domian object. so I am using foreach loop to iterate the profileDTO and set the list of dueDiligence into separate Domain object. – escort May 16 '19 at 07:31