Book.json
[{
"title": "Hunger Games",
"description": " fast paced In a not-too-distant future, the United States of America has collapsed, weakened by drought, fire, famine, and war, to be replaced by Panem, a country divided into the Capitol and 12 districts. Each year, two young representatives from each district are selected by lottery to participate in The Hunger Games. Part entertainment, part brutal intimidation of the subjugated districts, the televised games are broadcast throughout Panem as the 24 participants are forced to eliminate their competitors, literally, with all citizens required to watch. When 16-year-old Katniss s young sister, Prim, is selected as the mining district s female representative, Katniss volunteers to take her place. She and her male counterpart, Peeta, the son of the town baker who seems to have all the fighting skills of a lump of bread dough, will be pitted against bigger, stronger representatives who have trained for this their whole lives. Collins s characters are completely realistic and sympathetic as they fight and form alliances literary distant future great man and friendships in the face of distant future overwhelming odds; the plot is tense, dramatic, and engrossing. This book will definitely resonate with the generation raised on reality shows like Survivor and American Gladiator. Book one of a planned trilogy."
}]
public class FileReader {
public static void main(String[] args) {
// TODO Auto-generated method stub
String keywordCsv= "resources/addresses.csv";
String booksJson ="resources/books.json";
//Csvfilereader.processBySplit(fileName);
Csvfilereader csvReader= new Csvfilereader();
//ReadJson readjson =new ReadJson();
ObjectMapper csvobj;
ObjectMapper descriptionJsonobj=new ObjectMapper() ;
MapType type = descriptionJsonobj.getTypeFactory().constructMapType(
Map.class, String.class, Object.class);
try {
csvobj= csvReader.processByStreamApi(keywordCsv);
Map<String,Object> jsonMap = descriptionJsonobj.readValue(booksJson, type);
jsonMap.forEach((k,v) -> System.out.println((k +": "+ v)));
}
catch(Exception e) {
e.printStackTrace();
}
System.out.println("Successfull");
//JsonObjectFormatVisitor
}
}
После запуска программы следующее исключение дает
com.fasterxml.jackson.core.JsonParseException: Unrecognized token 'resources': was expecting ('true', 'false' or 'null')
at [Source: (String)"resources/books.json"; line: 1, column: 10]
Successfull
at com.fasterxml.jackson.core.JsonParser._constructError(JsonParser.java:1804)
at com.fasterxml.jackson.core.base.ParserMinimalBase._reportError(ParserMinimalBase.java:703)
at com.fasterxml.jackson.core.json.ReaderBasedJsonParser._reportInvalidToken(ReaderBasedJsonParser.java:2853)
at com.fasterxml.jackson.core.json.ReaderBasedJsonParser._handleOddValue(ReaderBasedJsonParser.java:1899)
at com.fasterxml.jackson.core.json.ReaderBasedJsonParser.nextToken(ReaderBasedJsonParser.java:757)
at com.fasterxml.jackson.databind.ObjectMapper._initForReading(ObjectMapper.java:4141)
at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:4000)
at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:3042)
at com.readcsv.FileReader.main(FileReader.java:28)
Я новичок в Java. Я должен сопоставить Keword из CSV-файла с файлом books.json. Я использую Джексона ObjectMapper.