This repository was archived by the owner on Jan 22, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 76
Deserializing an empty string as an array field return a non-empty list of one empty String #66
Copy link
Copy link
Closed
Milestone
Description
I have a csv with 11 columns separated with tabulation the last one is an array separated by pipes.
I've declared a schema for the maping.
When the array field have one or many values it works fine, but when it has no value, instead of an empty list, i get a list of one empty String "".
I've found this thread http://stackoverflow.com/questions/12933394/jackson-deserialize-as-an-empty-list but, even with adding the DeserializationFeature presented it didn't change anything (i've try with and withFeatures, i don't see the difference?).
Even if i can't modify the source file, i've tried with quotes, it doesn't change anything.
CsvSchema schema = CsvSchema.builder()
.setColumnSeparator('\t')
.setArrayElementSeparator('|')
.disableEscapeChar()
.disableQuoteChar()
.setUseHeader(false)
.setNullValue("")
.addNumberColumn("extId") // 0
.addNumberColumn("intId") // 1
.addNumberColumn("pct") // 2
.addNumberColumn("mask") // 3
.addColumn(Column.PLACEHOLDER) // 4
.addColumn("singName") // 5
.addColumn("PlurName") // 6
.addColumn(Column.PLACEHOLDER) // 7
.addColumn(Column.PLACEHOLDER) // 8
.addColumn(Column.PLACEHOLDER) // 9
.addArrayColumn("aliases") // 10
.build();
CsvMapper mapper = new CsvMapper();
this.it = mapper
.reader(clazz)
.withFeatures(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT,
DeserializationFeature.ACCEPT_EMPTY_ARRAY_AS_NULL_OBJECT,
DeserializationFeature.USE_JAVA_ARRAY_FOR_JSON_ARRAY)
.with(schema)
.readValues(reader);
According to the idea of the thread i've modified my setter, but it's not a good solution.
@JsonProperty("aliases")
public void setAliases(List<String> aliases) {
if (aliases == null || (aliases.size() == 1 && "".equals(aliases.get(0))))
this.aliases = new ArrayList<String>();
else
this.aliases = aliases;
}
Maybe i've missed something?
Metadata
Metadata
Assignees
Labels
No labels