当前位置:网站首页>New typereference usage fastjson[easy to understand]

New typereference usage fastjson[easy to understand]

2022-06-25 18:05:00 Full stack programmer webmaster

Hello everyone , I meet you again , I'm your friend, Quan Jun .

new TypeReference usage fastjson

Personally, there are many scenes involved , Most of the information I get by calling other people's interfaces , Then map the case of the entity . When you don't know this method, every time you get a string and want to map an object , Just jsonobject All kinds of transformations , I don't want to read the code I wrote , Don't talk much about code !!!

        // This new typeReference The imported package is package com.alibaba.fastjson;
        // It also has a bag package com.fasterxml.jackson.core.type;
        /** * This is a conversion list Example , To object or map It's about the same  **/
        String provinces = readJsonFile(".//areaCode//provinces.json");
        List<NationalCityCode> provinceList = jsonObject.parseObject(provinces, new TypeReference<List<NationalCityCode>>() { 
   });
        for (NationalCityCode province : provinceList) { 
   
            redisTemplate.opsForValue().set(province.getCode(), province.getName());
        }
/** * Turn to object  **/
String provinces = readJsonFile(".//areaCode//provinces.json");
NationalCityCode province = jsonObject.parseObject(provinces, new TypeReference<NationalCityCode>() { 
   });
        for (NationalCityCode province : provinceList) { 
   
            redisTemplate.opsForValue().set(province.getCode(), province.getName());
        }

Publisher : Full stack programmer stack length , Reprint please indicate the source :https://javaforall.cn/151110.html Link to the original text :https://javaforall.cn

原网站

版权声明
本文为[Full stack programmer webmaster]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/176/202206251753412158.html