Java Opencsv,StatefulBeanToCsv将对象的嵌套列表写入csv

Java Opencsv,StatefulBeanToCsv将对象的嵌套列表写入csv,java,list,csv,opencsv,writetofile,Java,List,Csv,Opencsv,Writetofile,我必须使用open Csv将对象的嵌套列表(StoreLocations)写入Csv文件。 我的模型课是- public class StoreLocation { private String name; private String city; private int zip; private String streetAndNumber; private List<String> keywords; private Double

我必须使用open Csv将对象的嵌套列表(StoreLocations)写入Csv文件。 我的模型课是-

public class StoreLocation {
    private String name;
    private String city;
    private int zip;
    private String streetAndNumber;
    private List<String> keywords;
    private Double lat;
    private Double lng;
    private List<OpeningHours> openingHours;
}

public class OpeningHours {
    private String dayOfWeek;
    private String from1;
    private String to1;
}
注意:我试着使用super csv()引用,但是它非常复杂,而且我不知道如何将它写入文件

此外,我还参考了将复杂/嵌套java对象写入csv over stackoverflow的所有文章

public void getStoreLocationData(List<StoreLocation> storeLocations) throws IOException, CsvDataTypeMismatchException, CsvRequiredFieldEmptyException {
        try (
                Writer writer = Files.newBufferedWriter(Paths.get(storeLocationDataCsv))
        ) {
            StatefulBeanToCsv beanToCsv = new StatefulBeanToCsvBuilder(writer)
                    .withQuotechar(CSVWriter.NO_QUOTE_CHARACTER)
                    .build();
            beanToCsv.write(storeLocations);
        }
    }
[{
"name":"OBI Markt Kempen",
"city":"Kempen",
"zip":47906,
"streetAndNumber":"Kleinbahnstraße 32",
"keywords":[],
"lat":51.3740233,
"lng":6.4182039,
"openingHours":
[{"dayOfWeek":"1","from1":"08:00","to1":"20:00"},
{"dayOfWeek":"2","from1":"08:00","to1":"20:00"},
]}]