Optional<List<Spot>> geoData = getGeoCodeBat(geocodeRequestDTO, reportResponseDTO); //declaration of geoData
//**geoData is a list of object**
// **getting syntax error in map**
// **Errors is an array inside geocodes**
geoData.get().stream().map(m -> {
Arrays.stream(m.getErrors()).forEach(i ->{
if(i.getType()==1) //Type is an field inside the Errors array
{
reportResponseDTO.setStatus(HttpStatus.BAD_REQUEST); //setting bad request in response
reportResponseDTO.setStatusCode(400); // setting the bad request value
}
});
最佳答案
不知道我是否正确回答了您的问题。但是您可以尝试以下方法:
boolean isBadRequest = geoData.orElseGet(Collections::emptyList)
.stream()
.map(Spot::getErrors)
.flatMap(Arrays::stream)
.anyMatch(i -> i.getType() == 1);
if (isBadRequest) {
reportResponseDTO.setStatus(HttpStatus.BAD_REQUEST);
reportResponseDTO.setStatusCode(400);
}
关于java - 使用流从对象列表中包含的数组检索类型时出错,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/58527691/