'Jackson CsvMapper to map object with a map of maps to csv
I have a complex java object that I want to map to csv using Jacksons CsvMapper.
public class TestObject {
private Map<String, Map<String, String>> values;
@JsonAnyGetter
public Map<String, Map<String, String>> getValues() {
return values;
}
@JsonAnySetter
public void setValues(Map<String, Map<String, String>> values) {
this.values = values;
}
}
The object is a list of TestObjects:
CsvMapper mapper = new CsvMapper();
CsvSchema schema = mapper.schemaFor(clazz).withUseHeader(true);
ObjectWriter myObjectWriter = mapper.writer(schema);
return myObjectWriter.writeValueAsString(objectList);
However when I try to map this to csv, I get an error due to the values in the map since its a map of map.
Caused by: com.fasterxml.jackson.dataformat.csv.CsvMappingException: Unrecognized column 'test_column': known columns: ....
Does anyone know how I can get jacksons csvmapper to correctly convert this map of maps to csv?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
