Bonjour le monde,

j'ai besoin d'écrire des propriétés d'une liste d'objets Words dans un fichier CSV.

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
 
import com.fasterxml.jackson.databind.ObjectWriter;
import com.fasterxml.jackson.dataformat.csv.CsvMapper;
import com.fasterxml.jackson.dataformat.csv.CsvParser;
import com.fasterxml.jackson.dataformat.csv.CsvSchema;
 
public class WordsToCvs {
 
	public static void main(String[] args) {
 
// Création d'une liste de mots.
// Un mot est de la forme Word [id=1, word=mot1, language=en-gb, lexicalEntries=null, pronunciations=null, type=type1]
		List<Word> words = new ArrayList<Word>();
		WordsList wordsList = new WordsList("src/resources/listWords.txt");
		wordsList.init();
		wordsList.createListWords();
		words = wordsList.getWords();
 
// Création d'un schéma.
		CsvSchema schema = CsvSchema.builder()
				.addColumn("id")
				.addColumn("word")
				.addColumn("language")
				.addColumn("type")
				.build();
		schema = schema.withColumnSeparator(';');
 
// Création d'un mapper
		CsvMapper mapper = new CsvMapper();
		mapper.enable(CsvParser.Feature.WRAP_AS_ARRAY);
 
// Ecriture du fichier CSV
		ObjectWriter writer = mapper.writer(schema.withLineSeparator("\n"));
		try {
			writer.writeValue(new File("words.csv"), words);
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}
Mais le compilateur me retourne l'erreur suivante :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
 
com.fasterxml.jackson.dataformat.csv.CsvMappingException: 
Unrecognized column 'lexicalEntries': known columns:
 ["id","word","language","type"] (through reference chain: java.util.ArrayList[0]->dictionary.Word["lexicalEntries"])
Comment ne pas prendre en charge certains attributs du mot ?