通過ObjectMapper將實體轉成字串 ,將 用json存的的list 迴轉list
阿新 • • 發佈:2019-05-15
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);