11package com .somemore .domains .volunteerrecord .repository ;
22
3+ import com .fasterxml .jackson .annotation .JsonInclude ;
4+ import com .fasterxml .jackson .databind .DeserializationFeature ;
5+ import com .fasterxml .jackson .databind .ObjectMapper ;
36import com .somemore .domains .volunteerrecord .dto .response .VolunteerMonthlyRankingResponseDto ;
47import com .somemore .domains .volunteerrecord .dto .response .VolunteerRankingResponseDto ;
58import com .somemore .domains .volunteerrecord .dto .response .VolunteerTotalRankingResponseDto ;
@@ -31,13 +34,29 @@ public void saveRanking(VolunteerRankingResponseDto rankings) {
3134
3235 @ SuppressWarnings ("unchecked" )
3336 public Optional <VolunteerRankingResponseDto > getRankings () {
37+ ObjectMapper mapper = new ObjectMapper ();
38+
39+ mapper .configure (DeserializationFeature .FAIL_ON_UNKNOWN_PROPERTIES , false );
40+ mapper .setSerializationInclusion (JsonInclude .Include .NON_NULL );
41+ mapper .enable (DeserializationFeature .ACCEPT_SINGLE_VALUE_AS_ARRAY );
3442
3543 List <VolunteerTotalRankingResponseDto > totalRanking =
36- (List <VolunteerTotalRankingResponseDto >) redisTemplate .opsForValue ().get (TOTAL_RANKING_KEY );
44+ (List <VolunteerTotalRankingResponseDto >) Optional .ofNullable (redisTemplate .opsForValue ().get (TOTAL_RANKING_KEY ))
45+ .map (obj -> mapper .convertValue (obj ,
46+ mapper .getTypeFactory ().constructCollectionType (List .class , VolunteerTotalRankingResponseDto .class )))
47+ .orElse (null );
48+
3749 List <VolunteerMonthlyRankingResponseDto > monthlyRanking =
38- (List <VolunteerMonthlyRankingResponseDto >) redisTemplate .opsForValue ().get (MONTHLY_RANKING_KEY );
50+ (List <VolunteerMonthlyRankingResponseDto >) Optional .ofNullable (redisTemplate .opsForValue ().get (MONTHLY_RANKING_KEY ))
51+ .map (obj -> mapper .convertValue (obj ,
52+ mapper .getTypeFactory ().constructCollectionType (List .class , VolunteerMonthlyRankingResponseDto .class )))
53+ .orElse (null );
54+
3955 List <VolunteerWeeklyRankingResponseDto > weeklyRanking =
40- (List <VolunteerWeeklyRankingResponseDto >) redisTemplate .opsForValue ().get (WEEKLY_RANKING_KEY );
56+ (List <VolunteerWeeklyRankingResponseDto >) Optional .ofNullable (redisTemplate .opsForValue ().get (WEEKLY_RANKING_KEY ))
57+ .map (obj -> mapper .convertValue (obj ,
58+ mapper .getTypeFactory ().constructCollectionType (List .class , VolunteerWeeklyRankingResponseDto .class )))
59+ .orElse (null );
4160
4261 if (totalRanking == null || monthlyRanking == null || weeklyRanking == null ) {
4362 return Optional .empty ();
@@ -49,4 +68,6 @@ public Optional<VolunteerRankingResponseDto> getRankings() {
4968 weeklyRanking
5069 ));
5170 }
71+
72+
5273}
0 commit comments