Jackson Json:将Json树节点转换为Java对象并将其添加到ArrayList

Jackson Json:将Json树节点转换为Java对象并将其添加到ArrayList,java,json,arraylist,jackson,Java,Json,Arraylist,Jackson,我对Java和解析Json还是新手。我正在尝试用Spring构建一个漫画Web应用程序。数据库是一个Json文件,其中包含一系列不同的漫画。 我想将Json数组转换为Java对象,并将其放入ArrayList中,但我似乎在某个地方犯了一个错误。也许你能告诉我我做错了什么?在执行JUnit测试时,我遇到以下错误: Error com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized field "C

我对Java和解析Json还是新手。我正在尝试用Spring构建一个漫画Web应用程序。数据库是一个Json文件,其中包含一系列不同的漫画。 我想将Json数组转换为Java对象,并将其放入ArrayList中,但我似乎在某个地方犯了一个错误。也许你能告诉我我做错了什么?在执行JUnit测试时,我遇到以下错误:

Error com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized field "Comic" (class de.uni_koeln.comics.data.Comic), not marked as ignorable (6 known properties: , "title", "issue", "id", "box", "publisher", "comment"])
 at [Source: N/A; line: -1, column: -1] (through reference chain: de.uni_koeln.comics.data.Comic["Comic"])
喜剧类

package de.uni_koeln.comics.data;

import de.uni_koeln.comics.service.JsonImportService;

public class Comic {
    private JsonImportService jservice;

public String title;
public int id;
public int issue;
public int box;
public String publisher;
public String comment;

public Comic() {

}
public Comic(String title, int issue, int box, String publisher, String   comment) {
        this.title = title;
        this.issue = issue;
        this.box = box;
        this.comment = comment;
        this.publisher = publisher;
    }

//setter and getter
` JsonImportService

package de.uni_koeln.comics.service;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;


@Service
public class JsonImportService {
    private List<Comic> comicList;

    @Test
    public void readComicJson() throws JsonParseException, JsonMappingException, IOException {

        ObjectMapper mapper = new ObjectMapper();
        JsonNode root = mapper.readTree(new File("src/main/resources/Comics.json"));
    Comic comic = mapper.treeToValue(root, Comic.class);

    JsonNode contactNode = root.path("Comic");
    if (contactNode.isArray()) {
        for (JsonNode node : contactNode) {

            String title = node.path("Title").asText();
            int issue = node.path("Issue #").asInt();
            int box = node.path("Box #").asInt();
            String publisher = node.path("Publisher").asText();
            String comment = node.path("Comments").asText();

            comic.setTitle(title);
            comic.setIssue(issue);
            comic.setBox(box);
            comic.setPublisher(publisher);
            comic.setComment(comment);
            comicList.add(new Comic(title,box,issue,publisher,comment));
        }
    }
}

public List<Comic> getComicList() {
    return comicList;
}
package de.uni_koeln.com.service;
导入java.io.File;
导入java.io.IOException;
导入java.util.ArrayList;
@服务
公共类JsonImportService{
私人名单喜剧演员;
@试验
public void readComicJson()抛出JsonParseException、JsonMappingException、IOException{
ObjectMapper mapper=新的ObjectMapper();
JsonNode root=mapper.readTree(新文件(“src/main/resources/Comics.json”);
Comic Comic=mapper.treeToValue(根,Comic.class);
JsonNode contactNode=root.path(“Comic”);
if(contactNode.isArray()){
for(JsonNode节点:contactNode){
字符串title=node.path(“title”).asText();
int issue=node.path(“issue#”).asInt();
int-box=node.path(“box#”).asInt();
字符串publisher=node.path(“publisher”).asText();
String comment=node.path(“Comments”).asText();
漫画。片名(片名);
漫画集(第期);
漫画.立盒(盒);
漫画出版社(出版商);
comic.setComment(评论);
添加(新漫画(标题、框、期、出版商、评论));
}
}
}
公共列表getComicList(){
回归喜剧;
}

尝试使用类似blow的
@JsonIgnoreProperties
注释

@JsonIgnoreProperties(ignoreUnknown=true)

公共类漫画{

}


你能发布你的json文件吗?