2

i am using model mapper library and i am facing with a problem

-> it's returning null value only when it's date types, bellow is my code.

@Component
@RequiredArgsConstructor
public class RedisUtil {
    private HashOperations<String, String, Object> hashOperations;

    @Qualifier("objectRedisTemplate")
    private final RedisTemplate<String, Object> redisTemplate;

    private final ModelMapper modelMapper;


    @PostConstruct
    public void init() {
        this.hashOperations = redisTemplate.opsForHash();
    }


    // todo : model mapper date null 나오는거 수정
    public <T> T get(String key, String hashKey, Class<T> type) {
        Object o = hashOperations.get(key, hashKey);
        if ( o instanceof LinkedHashMap) {
            return modelMapper.map(o, type);
        }else {
            return (T)o;
        }
    }

    public <T> void save(String key, String hashKey, Object object) {
        hashOperations.put(key, hashKey, object);
    }

    public <T> List<T> getAll(String key, Class<T> type) {
        List<T> list = new ArrayList<>();
        for (Object o : hashOperations.values(key)) {
            if ( o instanceof LinkedHashMap) {
                list.add(modelMapper.map(o, type));
            }else {
                list.add((T)o);
            }
        }
        return list;
    }

    public boolean isEmpty(String key, String hashKey) {
        return hashOperations.hasKey(key, hashKey);
    }

    public void remove(String key, String hashKey) {
        hashOperations.delete(key, hashKey);
    }

}

that's my code. and when i try to use method of get() or getAll() they return null value only on the date type

like this

Response(seqServiceBanner=37, serviceNo=1, serviceCode=TEST, title=test-title, url=www.test-url.com, link=www.test-link.com, startDate=null, endDate=null, adminId=test-amdin)

this name's matching is correct.

hongse
  • 43
  • 3

0 Answers0