How to make the spring batch Itemreader return a list by reading from a file

Asked

Viewed 29 times

0

In Spring Batch does anyone know how to make Flatfileitemreaderbuilder return a list? Or if there is any other class that reads the file and returns a list?
I have this Reader code:

  fun readFilesWithFixedPosition(
        @Value("#{jobParameters['arquivoClientes']}")
        customerFile: Resource
    ): FlatFileItemReader<List<Cadpos>> {

        return FlatFileItemReaderBuilder<List<Cadpos>>()
            .name("readFilesWithFixedPosition")
            .resource(customerFile)
            .fixedLength()
            .columns(*columns)
            .names(*names)
            .strict(false)
            .targetType(getObjectType())
            .build()
    }

    fun getObjectType(): Class<List<Cadpos>> {
        val myList: List<Cadpos> = ArrayList()
        return myList.javaClass
    }

But when reading this error is returned:

Caused by: org.springframework.beans.NotWritablePropertyException: Invalid property 'telefone' of bean class [java.util.ArrayList]: Bean property 'telefone' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
    at org.springframework.beans.BeanWrapperImpl.createNotWritablePropertyException(BeanWrapperImpl.java:243)
    at org.springframework.beans.AbstractNestablePropertyAccessor.processLocalProperty(AbstractNestablePropertyAccessor.java:432)
    at org.springframework.beans.AbstractNestablePropertyAccessor.setPropertyValue(AbstractNestablePropertyAccessor.java:278)
    at org.springframework.beans.AbstractNestablePropertyAccessor.setPropertyValue(AbstractNestablePropertyAccessor.java:266)
    at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:104)
    at org.springframework.validation.DataBinder.applyPropertyValues(DataBinder.java:851)
    at org.springframework.validation.DataBinder.doBind(DataBinder.java:747)
    at org.springframework.validation.DataBinder.bind(DataBinder.java:732)
    at org.springframework.batch.item.file.mapping.BeanWrapperFieldSetMapper.mapFieldSet(BeanWrapperFieldSetMapper.java:199)
    at org.springframework.batch.item.file.mapping.DefaultLineMapper.mapLine(DefaultLineMapper.java:43)
    at org.springframework.batch.item.file.FlatFileItemReader.doRead(FlatFileItemReader.java:185)
    ... 57 common frames omitted

As if after I converted to return a list I could no longer map the object. Does anyone have any idea how to fix?

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.