请求里面 用到 token 身份验证 还有data 于是打算写成泛型
package com.icss.bean;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.AllArgsConstructor;
import lombok.Getter;
import java.sql.Timestamp;
import java.util.List;
/**
* 接口传参 公用类
* @author Haiming
* @date 2020/10/21 9:16 AM
*/
@Getter
@AllArgsConstructor
public class RequestArrayData<T> {
private String token;
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Timestamp requestDate;
private List<T> data;
}
定义如下类 接收参数
package com.icss.bean;
import lombok.Getter;
import java.sql.Timestamp;
import java.util.List;
/**
* @author Haiming
* @date 2020/10/21 3:27 PM
*/
@Getter
public class VisualInventoryData extends RequestArrayData<VisualInventoryData>{
private String whCode;
private String position;
private String brandCode;
private String brandName;
private Long num1;
private Long lockNum;
private Double positionLockInRatio;
public VisualInventoryData(String token, Timestamp requestDate, List<VisualInventoryData> data) {
super(token, requestDate, data);
}
}
传json 转实体类的时候 异常了
org.springframework.http.converter.HttpMessageConversionException: Type definition error: [simple type, class com.icss.bean.VisualInventoryData]; nested exception is com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Cannot construct instance of `com.icss.bean.VisualInventoryData` (no Creators, like default construct, exist): cannot deserialize from Object value (no delegate- or property-based Creator)
at [Source: (PushbackInputStream); line: 2, column: 5]
at org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter.readJavaType(AbstractJackson2HttpMessageConverter.java:242)
at org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter.read(AbstractJackson2HttpMessageConverter.java:227)
at org.springframework.web.servlet.mvc.method.annotation.AbstractMessageConverterMethodArgumentResolver.readWithMessageConverters(AbstractMessageConverterMethodArgumentResolver.java:204)
at org.springframework.web.servlet.mvc.method.annotation.RequestResponseBodyMethodProcessor.readWithMessageConverters(RequestResponseBodyMethodProcessor.java:157)
at org.springframework.web.servlet.mvc.method.annotation.RequestResponseBodyMethodProcessor.resolveArgument(RequestResponseBodyMethodProcessor.java:130)
at org.springframework.web.method.support.HandlerMethodArgumentResolverComposite.resolveArgument(HandlerMethodArgumentResolverComposite.java:124)
at org.springframework.web.method.support.InvocableHandlerMethod.getMethodArgumentValues(InvocableHandlerMethod.java:165)
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:138)
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:102)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:895)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:800)
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1038)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:942)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:998)
at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:901)
spring参数接收如下
@PostMapping(value = "/industrialWmsElevatedLibrary")
@Log("工业WMS 高架库 数据同步")
@ApiOperation("工业WMS 高架库 数据同步")
public Result industrialWmsElevatedLibrary( @RequestBody VisualInventoryData resources){
VisualInventoryService.insertOrUpdate(resources,VisualInventoryDataType.INDUSTRIAL_WMS_ELEVATED_LIBRARY);
return Result.success("请求成功");
}
查了很多文档 貌似需要 TypeReference 那么 我要怎么处理呢 求大佬指定