JSON parse error: Cannot deserialize instance of java.util.ArrayList<com.sangfor.ngsoc.knowledge.to.UserEntity>
out of START_OBJECT token;
1. problem replication
① First, configure both knowledge and auth services into eureka.
eureka:
client:
serviceUrl:
defaultZone: http://localhost:8761/eureka/
② The project path of auth service is:
server:
port: 8081
servlet.context-path: /ngso/AUTH/
③ Interface of remote auth service:
@Api(tags = "Usersheet")
@Slf4j
@Validated
@RestController
@ResponseResult
@RequestMapping("/api/v2")
public class UserController {
@Autowired
private IUserService userService;
@PostMapping("/users/inner/exact")
public PageData<UserEntity> exactPageQueryUserList(@Validated @RequestBody UserQo userQo,
@RequestParam(SessionKey.DOMAIN_ID) String domainId) {
userQo.setDomainId(domainId);
return userService.exactPageQueryUserList(userQo);
}
}
④ Feign interface of knowledge service, calling the interface of remote auth service:
@FeignClient(name = "AUTH")
public interface AuthFeignService {
@PostMapping("/ngso/AUTH/api/v2/users/inner/exact")
PageData<UserResp> exactPageQueryUserList(
@RequestBody UserReqDto userReqDto,
@RequestParam(SessionKey.DOMAIN_ID) String domainId);
}
(5) calling feign interface in knowledge service:
@Override
public String addDoc() {
List<String> userIds = new ArrayList<>();
UserInfo userInfo = UserInfoShareHolder.getUserInfo();
userIds.add(userInfo.getId());
UserReqDto userReqDto = new UserReqDto(userIds);
userReqDto.setPageNum(1);
userReqDto.setPageSize(1);
PageData<UserResp> pageDataApiResponse = authFeignService
.exactPageQueryUserList(userReqDto, UserInfoShareHolder.getUserInfo().getDomainId());
}
Result error:
JSON parse error: Cannot deserialize instance of `java.util.ArrayList<com.sangfor.ngsoc.knowledge.to.UserEntity>` out of START_OBJECT token;
2. Solutions
① First, directly call the auth service interface without using the remote service: localhost: 8081/NGSO/auth/API/V2/users/inner/exact
There are more code and message messages than the actual response data, indicating that the response data is encapsulated
{
"code": 0,
"message": "成功",
"data": {
"pageNum": 1,
"pageSize": 1,
"totalCount": 1,
"data": [
{
"id": "fx-user-fec844b9e0dc0d80000004",
"name": "sysadmin",
"phone": "",
"email": "",
"description": "Built-in user: default platform system administrator account",
"domainId": "fx-domain-fec833bfa0dbcc40000001",
"projectId": " ",
"enabled": 1,
"createTime": "2021-10-18 15:41:17",
"updateTime": "2021-10-21 16:35:11",
"changeTime": "2021-10-18 16:44:37",
"loginTime": "2021-10-21 16:35:11",
"options": 0,
"builtIn": 1
}
]
}
}
② View the code and add a layer of encapsulation:
@FeignClient(name = "AUTH" )
public interface AuthFeignService {
@PostMapping("/ngso/AUTH/api/v2/users/inner/exact")
ApiResponse<PageData<UserResp>> exactPageQueryUserList(
@RequestBody UserReqDto userReqDto,
@RequestParam(SessionKey.DOMAIN_ID) String domainId);
}
Read More:
- [Solved] SpringBoot Date Convert Error: JSON parse error: Cannot deserialize value of type `java.time.LocalDateTime`
- [Solved] JSON parse error: Cannot construct instance of
- Exception information: jsonmappingexception: out of start_ ARRAY token
- [Solved] Scala error: type mismatch; found : java.util.List[?0] required: java.util.List[B]
- [Solved] java.util.concurrent.ExecutionException: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Tomcat].StandardHost[localhost].StandardContext[]]
- [Solved] HttpMessageNotReadableException: JSON parse error: Unrecognized field “xxxx“
- [Solved] Java.util.linkedhashmap cannot be cast to entity class
- [Solved] org.springframework.http.converter.HttpMessageNotReadableException: JSON parse error: Cannot
- org.springframework.http.converter.HttpMessageNotReadableException: JSON parse error: Cannot deseria
- Comparison between ArrayList and HashMap
- Uncaught SyntaxError: Unexpected token o in JSON at position 1 [How to Solve]
- JSON parse error: invalid UTF-8 solution series [How to Solve]
- [Solved] Java.lang.ClassCastException: [Ljava.lang.Long; cannot be cast to java.util.List
- [Solved] Feign Call Port Error: HttpMessageNotReadableException:JSON parse error:Illegal character ((CTRL-CHAR, code 31)
- [How to Solve Error]java.util.Date cannot be cast to java.sql.Date
- [Solved] Failed to convert value of type ‘java.lang.String‘ to required type ‘java.util.Date‘;
- Java Error: No enclosing instance of type Main is accessible. Must qualify the allocation with an encl
- [Solved] Tomcat Error: org.apache.tomcat.util.digester.Digester.fatalError Parse fatal error at line [40] column [36]
- [Solved] Failed to instantiate java.util.List using constructor NO_CONSTRUCTOR with arguments
- Consumer service instance error: HTTP get http://xxx/actuator/health: 503 output: {“status”: “out_of_service”