https://kotlinlang.org logo
#jackson-kotlin
Title
# jackson-kotlin
k

kenkyee

06/28/2021, 2:43 PM
Does anyone know how to get Jackson CSV to honor @JsonPropertyOrder? It does need the JsonProperty attached to the getter or it'll use the field name. But it doesn't seem to honor the order despite following the technique mentioned in a few Java Stackoverflow posts....i.e., disable alphabetical ordering and use @JsonPropertyOrder. The order it's emitting is: Module,FilePath,Line,Offset,Severity,UniqueID,Category,Description,ComplexityTotal,CoverageTotal,NumBlockers,NumCriticals,NumMajors,NumMinors,NumInfos,FileCount,LinesOfCode Which bizarrely isn't alphabetical and also not the same as the definition of the data class and isn't in @JsonPropertyOrder either 🤔
Code is pretty simple...
d

dinomite

06/28/2021, 2:55 PM
Interesting, the Kotlin module doesn’t do anything special in regards to property ordering
So my guess would be the use site targets, what happens if you change
get
to
field
(or just add an additional annotation targeted at
field
)?
k

kenkyee

06/28/2021, 5:40 PM
Using @field: made no difference either...super puzzled. also tried using field names in the @JsonPropertyOrder but made no difference 🤔
Copy code
@JsonPropertyOrder(
    "module", "filePath", "line", "offset", "severity", "uniqueId", "category", "description",
    "fileCount, linesOfCode", "complexityTotal", "coverageTotal",
    "numBlockers", "numCriticals", "numMajors", "numMinors", "numInfos"
)
I'm probably going to see if I can write up a sample and file an issue w/ it. Going to punt and use a more crude Kotlin CSV library instead (com.github.doyaaaaaken:kotlin-csv-jvm) because I need to get this to work soon...
ok..turned out I didn't need to use another library. Ended up setting the order using this technique since @JsonPropertyOrder seems broken:
Copy code
val schema = CsvSchema.builder()
    .addColumn("Module")
...
    .addColumn("NumMinors")
    .addColumn("NumInfos")
    .build()
    .withHeader()
Kinda hacky but 🤷
101 Views