0
votes

According to the "bindy" component from apache camel. https://camel.apache.org/components/latest/dataformats/bindy-dataformat.html I'm trying to unmarshal simple csv file with kotlin, but pojo filed values don't created.

I think the problem is in unmarshaling with kotlin.

model ->

@CsvRecord(separator = ",", skipField = true)
data class Product(

        @DataField(pos = 1, required = true)
        var id: String? = null,

        @DataField(pos = 2, required = true)
        var name: String? = null


) {
    override fun toString() = "Product(id=$id, name=$name)"
}

route ->

@Component
class ProductRoute : RouteBuilder() {
    override fun configure()  {

        val bindy = BindyCsvDataFormat(Product::class.java)

        from("file://src/main/resources?charset=Cp1250&fileName=products.csv&noop=true")
                .log("start -> \${body}")
                .unmarshal(bindy)
                .split(body())
                .log("end -> \${body}")
                .end()
    }
}

produtcts.csv ->

"1","productName1"
"2","productName2"

Log result ->

INFO  route1 - end -> Product(id=null, name=null)  
INFO  route1 - end -> Product(id=null, name=null)
1
When I dig deeper I found that the problem is in BindyCsvFactory.class field.getAnnotation(DataField.class) always return null. But annotation exists on fields. - user6522169

1 Answers

0
votes

The resolution was to add @field to Kotlin field annotation

@field:DataField(pos = 1, required = true)

accordingly to https://kotlinlang.org/docs/annotations.html#annotation-use-site-targets