-
-
Notifications
You must be signed in to change notification settings - Fork 149
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Jackson CSV not taking in account the first column #208
Comments
I can have a look, but I have one question first: I think example is missing something (perhaps |
@cowtowncode I have done some simplification and have added @JsonProperty to my Data Class data class StockElement(
@JsonProperty("EAN")
val ean: Long?,
@JsonProperty("LIB ARTICLE")
val label: String?,
@JsonProperty("QUANTITE")
val quantity: Int?,
@JsonProperty(value = "POIDS", required = false)
val weight: Int?
) and my test method val raw = """
EAN;LIB ARTICLE;QUANTITE;POIDS
3571211210979;CABLE ETH DRT CAT6 13M;0;836
3571211210979;CABLE ETH DRT CAT6 3M;0;836
""".trimIndent()
val mapper = CsvMapper()
.registerModule(KotlinModule())
val schema = CsvMapper()
.typedSchemaFor(StockElement::class.java)
.withHeader()
.withColumnSeparator(';')
val iterator: MappingIterator<StockElement> =
mapper.readerFor(StockElement::class.java)
.with(schema)
.readValues(raw)
val stockElements: List<StockElement> = iterator.readAll() Result is the same :
What I understand, it's Jackson uses JsonProperty and is searching for "EAN, POIDS, ..." when unmarshalling but don't find its. I don't understand why because there are present on the string I use as input :( |
Yeah, found a way to do it ... not sure if it is the simplest ... but it works I only changed stuff in the Data Class, I think it is necessary because of Kotlin :) data class StockElement(
@get:JsonProperty("EAN")
@param:JsonProperty("EAN")
val ean: String?,
@get:JsonProperty("LIB ARTICLE")
@param:JsonProperty("LIB ARTICLE")
val label: String?,
@get:JsonProperty("QUANTITY")
@param:JsonProperty("QUANTITY")
val quantity: Int?,
@get:JsonProperty("TAXE DEE")
@param:JsonProperty("TAXE DEE")
val deeeTax: String?
) |
Ok. Not sure why multiple annotations are needed (although yes, it is sort of Kotlin-specific), but I may have a clue: when creating |
Jackson Version : 2.11.1
In Kotlin, I have a csv file (simple)
I have some data class
and a simple main code
This code throws a strange error at runtime :
It is like the first column is not processed by Jackson :(
Very strange ... I think I am doing something wrong.
Any help appreciated.
The text was updated successfully, but these errors were encountered: