【发布时间】:2021-12-29 16:42:57
【问题描述】:
我需要发送有效载荷,下面是详细信息。我不确定错误是由于传递了空数组还是什么原因。请帮忙。感谢期待。 PS:出于安全考虑,我不得不手动输入密码。
SumAll sa = new SumAll();
sa.setAge(68);
int[] myTrueAge ={};
sa.setTrueAge(myTrueAge);
During req it should go as -> "TrueAge":[],)
SumAll gsa = given().header(----).body(sa).expect().defaultParser(Parser.JSON).when().post(----).as(sumAll.class)
Pojo 类:
public class SumAll{
private int Age;
private int[] TrueAge= {};
public int[] getTrueAge(){
return TrueAge;
public void setTrueAge(int[] TrueAge)
TrueAge = TrueAge;
}}
错误:
com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognised field "Allocation" (class pojo.SumAll), not marked as ignorable (14 known properties: ..…........ All properties are mentioned here.....
At [source : (String) " response is given here"
【问题讨论】:
-
呈现的代码中至少有两个语法错误。请确保这是产生错误的实际代码。此外,请正确格式化代码并遵循 getter 和 setter 的 java 命名约定 (
gettrueAge()->getTrueAge(),settrueAge(...)->setTrueAge(...))。 Jackson 可能会依赖那些确切的 getter 和 setter。 -
感谢您的快速回复。我已手动输入代码,因为我无法使用工作电脑。在实际应用中,我给出了正确的语法。
标签: java arrays string rest getter-setter