Post 在 jax rs jersey 中无法正常工作

Post in jax rs jersey not working correctly

这是Post方法...

@Path("science")
@POST
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public String postMultiple(Multiple getSuggestion) {
    Multiple postedQuestion = null;
    System.out.println(getSuggestion.getQuestion());
    System.out.println(getSuggestion.getOption1());
    System.out.println(getSuggestion.getOption2());
    System.out.println(getSuggestion.getOption3());
    System.out.println(getSuggestion.getAnswer());
    return "Post Works";
}

这里是多对象定义...

你可以看到我class正确

package in.webxstudio.rest.quiz.api.models;

import javax.xml.bind.annotation.XmlRootElement;


@XmlRootElement
public class Multiple {
private String Question,Option1,Option2,Option3,Answer;


public Multiple() {}

public Multiple(String Question,String Option1,String Option2,String Option3,String Answer) {
        this.Question=Question;
        this.Option1=Option1;
        this.Option2=Option2;
        this.Option3=Option3;
        this.Answer=Answer;
    }


public String getQuestion() {
    return this.Question;
}
public String getOption1() {
    return this.Option1;
}
public String getOption2() {
    return this.Option2;
}
public String getOption3() {
    return this.Option3;
}
public String getAnswer() {
    return this.Answer;
}

public void setQuestion(String question) {
    this.Question = question;
}
public void setOption1(String option1) {
    this.Option1 = option1;
}
public void setOption2(String option2) {
    this.Option2 = option2;
}
public void setOption3(String option3) {
    this.Option3 = option3;
}
public void setAnswer(String answer) {
    this.Answer = answer;
}
}

但是我在我的终端/控制台中得到了这个输出

我在 api 端点发布的输入如下

{
  "answer": "Blue Whale",
  "option1": "Orca",
  "option2": "Colossal Squid",
  "option3": "Giraffe",
  "question": "What is the largest animal currently on Earth?"
}

有人能说我做错了什么吗? 我该如何纠正这种行为

始终遵循 Java 的变量命名约定,例如 变量名称应以小写字母开头..

public class Multiple {
private String question,option1,option2,option3,answer;


public Multiple() {}

public Multiple(String question,String option1,String option2,String option3,String answer) {
    this.question=question;
    this.option1=option1;
    this.option2=option2;
    this.option3=option3;
    this.answer=answer;
}


public String getQuestion() {
    return this.question;
}
public String getOption1() {
    return this.option1;
}
public String getOption2() {
    return this.option2;
}
public String getOption3() {
    return this.option3;
}
public String getAnswer() {
    return this.answer;
}

public void setQuestion(String question) {
    this.question = question;
}
public void setOption1(String option1) {
    this.option1 = option1;
}
public void setOption2(String option2) {
    this.option2 = option2;
}
public void setOption3(String option3) {
    this.option3 = option3;
}
public void setAnswer(String answer) {
    this.answer = answer;
}
}