我的api测试有问题。
当我试图从api获取数据时,lombok返回null作为接受值,但是api中有实数值。
屏幕选择:https://prnt.sc/w98nt2
我的回答:
@Data
@Builder
@EqualsAndHashCode
@NoArgsConstructor
@AllArgsConstructor
@JsonIgnoreProperties(ignoreUnknown = true)
public class PositionStatResponceDto {
private Integer keywordTasksCount;
private Integer doneKeywordTasksCount;
private Integer tasksCount;
private Integer doneTasks;
}
我的步骤是extactbody和发送post请求公共类positionsteps{
PositionsController positionsController = new PositionsController();
@Step("Post body with url: http://prod.position.bmp.rocks/api/aparser/get-statistic")
public PositionStatResponceDto postBody(PositionStatDto positionStatDto) {
return positionsController
.getStatistic(positionStatDto)
.statusCode(200)
.extract().body().as(PositionStatResponceDto.class);
}
}
api json响应一旦得到正确。这意味着请求工作权:
{
"period": {
"20201224": {
"startTime": "2020-12-24 00:00:19",
"endTime": "2020-12-24 06:39:30",
"totalRequestsCount": 0,
"totalQueriesCount": 161887,
"totalQueriesDoneCount": 161887,
"totalFailCount": 161,
"successfulQueries": 161726,
"proxiesUsedCount": 6.49,
"retriesUsedCount": 0,
"avgSpeed": 13.74,
"tasksCount": 1537,
"doneTasks": 1537,
"keywordTasksCount": 725,
"doneKeywordTasksCount": 725,
"runTime": "06:39:11",
"avgTimePerKeyword": 0.15,
"keywordsLost": 0.1
}
},
"avg": {
"totalRequestsCount": 0,
"totalQueriesCount": 161887,
"totalQueriesDoneCount": 161887,
"totalFailCount": 161
}
}
我以与api类似的方式发出post请求:
{
"success": 1,
"data": {
"45.90.34.87:59219": [
"http"
],
"217.172.179.54:39492": [
"http"
],
"144.76.108.82:35279": [
"http"
],
"5.9.72.48:43210": [
"http"
],
"144.76.108.82:47165": [
"http"
],
"45.90.34.87:57145": [
"http"
],
"144.76.108.82:53108": [
"http"
],
...
} }
它与dto一起正常工作:
@Data
@Builder
@EqualsAndHashCode(exclude = "success")
@NoArgsConstructor
@AllArgsConstructor
@JsonIgnoreProperties(ignoreUnknown = true)
public class AparsersResponceDto {
private Integer success;
private Map<String, List<String>> data;
}
请帮帮我。我不明白第一个例子怎么了。每个dto值返回“null”。
1条答案
按热度按时间hc8w905p1#
dto与正在分析的响应的结构不匹配。您有一个嵌套结构,其中在dto上只希望接收基元值。在上层有一个包含两个字段的结构。
从这个例子我可以假设
period
是一对日期作为键和PositionStatResponceDto
作为一种价值观。因此,这意味着键值对中只有一个项与您定义的dto匹配,但忽略了所有其他嵌套结构元素。为此,引入新的 Package 器dto来处理嵌套结构是有意义的。例如