count()함수를 사용할 일이 있어 추가 후 데이터를 불러와봤다.
개수니깐 당연히 인티저겠거니 하고 받았더니 BigInteger를 인티저로 변환할 수 없다는 오류가 떴다.
java.lang.ClassCastException: class java.math.BigInteger cannot be cast to class java.lang.Integer (java.math.BigInteger and java.lang.Integer are in module java.base of loader 'bootstrap')
BigInteger를 예전에 어디서 한번 본거같은데 실제로 만나는것은 처음이다.
그래서 조금 알아보자면
그렇다. BigInteger는 값의 범위가 정해지지 않은것이다.
왜 그런가 생각해보니깐 빅데이터같은 경우 데이터의 개수가 인티저의 범위인 -2147483648 ~ 2147483647를 넘을 수도 있다는 생각이 들었다.(int는 4byte이니깐, 2^32를 한 뒤 반으로 가르면 저 범위이다. +의 경우에는 0도 포함이라 하나 줄었다)
그래서 리턴값이 bigint인듯하다.
공식 문서를 찾아보니 bigint를 리턴한다고 친절하게 명시되어있었다.
List<AgencyAndStoreDistanceDto> agencyAndStoreDistanceDtoList =
objects.stream().map(object ->
AgencyAndStoreDistanceDto.builder()
.agencyCode((String) object[0])
.name((String) object[1])
.distance((Double) object[2])
.totalCount(((BigInteger) object[3]).intValue())
.workCount(((BigInteger) object[4]).intValue())
.agencyStatus(StoreAgencyStatus.valueOf((String) object[5]))
.build()
).collect(Collectors.toList());