Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/314.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 我可以在函数前面加上“前缀”吗;获得;在Springboot中_Java_Json_Spring Boot_Serialization_Repository - Fatal编程技术网

Java 我可以在函数前面加上“前缀”吗;获得;在Springboot中

Java 我可以在函数前面加上“前缀”吗;获得;在Springboot中,java,json,spring-boot,serialization,repository,Java,Json,Spring Boot,Serialization,Repository,我有一个与MongoRepository关联的Mcq类,我想得到一个应用了几个更改(答案无序排列、问题抽取等)的Mcq实例。我声明了我的函数“myMcq.getInstance()”,但我不能这样做,因为每次我想在响应中发送Mcq时,JSON输出中都会出现错误,因为Springboot认为我的类中有一个“instance”属性 这是我的java类: @Document(collection = "Mcqs") public class Mcq { @Id public String id

我有一个与MongoRepository关联的Mcq类,我想得到一个应用了几个更改(答案无序排列、问题抽取等)的Mcq实例。我声明了我的函数“myMcq.getInstance()”,但我不能这样做,因为每次我想在响应中发送Mcq时,JSON输出中都会出现错误,因为Springboot认为我的类中有一个“instance”属性

这是我的java类:

@Document(collection = "Mcqs")
public class Mcq {
    @Id public String id;
    @DBRef public User creator;

    public String title;
    public String categoryID;
    public List<McqChapter> chapterList = new ArrayList<>();
    public Difficulty difficulty;

    public Mcq() {}

    public Mcq(String title) {
        this();
        this.title = title;
    }

    public ArrayList<String> getQuestionsIDs() {
        ArrayList<String> result = new ArrayList<>();

        for (McqChapter chapter : chapterList) result.addAll(chapter.getQuestionIDs());

        return result;
    }


    public McqInstance getInstance() {
        return new McqInstance(this);
    }
}
@文档(collection=“Mcqs”)
公共级Mcq{
@Id公共字符串Id;
@DBRef公共用户创建者;
公共字符串标题;
公共字符串类别ID;
public List chapterList=new ArrayList();
公共困难;
公共Mcq(){}
公共Mcq(字符串标题){
这个();
this.title=标题;
}
公共数组列表getQuestionsIDs(){
ArrayList结果=新建ArrayList();
for(McqChapter chapter:chapterList)result.addAll(chapter.getQuestionId());
返回结果;
}
公共McqInstance getInstance(){
返回新的McqInstance(此);
}
}
要防止错误,请添加到
getInstance()
方法:

@JsonIgnore 
public McqInstance getInstance() {
    return new McqInstance(this);
}
标记注释,指示基于内省的序列化和反序列化功能将忽略带注释的方法或字段。也就是说,它不应该被认为是“吸气剂”、“定位器”或“创造者”。 要防止此错误,请添加到
getInstance()
方法:

@JsonIgnore 
public McqInstance getInstance() {
    return new McqInstance(this);
}
标记注释,指示基于内省的序列化和反序列化功能将忽略带注释的方法或字段。也就是说,它不应该被认为是“吸气剂”、“定位器”或“创造者”。
在getInstance()方法上添加@JsonIgnore和/或在同一方法上添加@JsonIgnoreType噢,谢谢,我知道它可以用于属性,我不认为它也适用于函数!在getInstance()方法上添加@JsonIgnore和/或在同一方法上添加@JsonIgnoreType噢,谢谢,我知道它可以用于属性,我不认为它也适用于函数!为什么我应该使用
@JsonIgnoreType
而不是
@JsonIgnore
?我修复了打字错误为什么我应该使用
@JsonIgnoreType
而不是
@JsonIgnore
?我修复了打字错误