1. 程式人生 > >通過ObjectMapper將實體轉成字串 ,將 用json存的的list 迴轉list

通過ObjectMapper將實體轉成字串 ,將 用json存的的list 迴轉list

InvokingSecurityInfo invokingSecurityInfo;
ObjectMapper objectMapper = new ObjectMapper();
List<String> userAccountList=new ArrayList<>();
//將實體類存成字串
invokingSecurityInfo = invokingSecurityUtil.invokingSecurityInfoRepository.getFirstByAvaiStatus(1);
String a=new ObjectMapper().writeValueAsString(invokingSecurityInfo)
//將實體類存成字串
JavaType javaType =objectMapper.getTypeFactory().constructParametricType(ArrayList.class, String.class);
userAccountList = objectMapper.readValue(invokingSecurityUtil.redisService.get(INVOKING_USER_ACCOUNT).toString(), javaType);