Bootstrap

Json转指定泛型对象


    public static void main(String[] args) {
        Map<String, RedisDouyinStoreProductModel> map = new HashMap<>();
        RedisDouyinStoreProductModel model = new RedisDouyinStoreProductModel();
        model.setCover("ddddd");
        map.put("1", model);
        String s = JSON.toJSONString(map);
        System.out.println("s = " + s);
        Map<String, RedisDouyinStoreProductModel> stringRedisDouyinStoreProductModelMap = JSON.parseObject(s,
            new TypeReference<Map<String, RedisDouyinStoreProductModel>>() {});
        System.out.println("stringRedisDouyinStoreProductModelMap = " + stringRedisDouyinStoreProductModelMap);
    }

通过typeReference

;