猿问

Json 无法反序列化 Spring 中的实例错误

我正在尝试发送一个 json 长列表并从 db 中获取记录。


我的控制器是:


@Api(tags = Endpoint.RESOURCE_customer, description = "customer Resource")

@RestController

@RequestMapping(produces = MediaType.APPLICATION_JSON_VALUE,consumes = MediaType.APPLICATION_JSON_VALUE)

@ResponseStatus(HttpStatus.OK)

public class CustomerResourceController {


    private final customerService customerService;



    public CustomerResourceController(customerService customerService) {


        this.customerService = customerService;

    }


    @ApiOperation(

            value = "Return customer",

            response = customerDto.class, responseContainer="List"

    )

    @PostMapping(value = Endpoint.RRESOURCE_customer_ID)

    public List<customerDto> getCustomersByIds(@RequestBody List<Long> ids) {

        return customerService.findcustomerIds(ids);

    }


}

和客户端类是:


@Headers("Content-Type: " + MediaType.APPLICATION_JSON_VALUE)

public interface CustomerClient {


@RequestLine("POST /customer/customers/search")

    List<LocGrpDto> getCustomersByIds(@RequestBody @Validated List<Long> ids);

}

我使用 JSON 在邮递员中测试此服务:


{ "ids": [1,7,8] }


但我收到此错误:


{

    "timestamp": "2018-10-05T13:29:57.645+0000",

    "status": 400,

    "error": "Bad Request",

    "message": "Could not read document: Can not deserialize instance of java.util.ArrayList out of START_OBJECT token\n at [Source: java.io.PushbackInputStream@3cb8b584; line: 1, column: 1]; nested exception is com.fasterxml.jackson.databind.JsonMappingException: Can not deserialize instance of java.util.ArrayList out of START_OBJECT token\n at [Source: java.io.PushbackInputStream@3cb8b584; line: 1, column: 1]",

    "path": "/api/v1/customer/customers/search",

    "errors": []

}

问题是什么?您在这里看到任何问题吗,或者可能是由于我的服务类或 dto 类引起的?


蝴蝶刀刀
浏览 348回答 1
1回答
随时随地看视频慕课网APP

相关分类

Java
我要回答