Hutool

  • JSONObject to bean

  • bean to str

  • user to UserDTO

  • bean to map

  • map to UserDTO

import cn.hutool.json.JSONUtil;
import cn.hutool.core.bean.BeanUtil;

// jsonObject to bean
Class<R> type 
JSONObject jsonObject = (JSONObject)redisData.getData();
R r = JSONUtil.toBean(jsonObject, type);

// bean to str
String str = JSONUtil.toJsonStr(shop)

// user to UserDTO
UserDTO userDTO = BeanUtil.copyProperties(user, UserDTO.class);

// bean to map
Map<String, Object> userMap = BeanUtil.beanToMap(userDTO, new HashMap<>(),
                CopyOptions.create()
                        .setIgnoreNullValue(true)
                        .setFieldValueEditor((fieldName, fieldValue) -> fieldValue.toString()));

// map to UserDTO
Map<Object, Object> userMap = stringRedisTemplate.opsForHash().entries(tokenKey);
UserDTO userDTO = BeanUtil.fillBeanWithMap(userMap, new UserDTO(), false);