当前位置:网站首页>new TypeReference用法 fastjson[通俗易懂]
new TypeReference用法 fastjson[通俗易懂]
2022-06-25 17:55:00 【全栈程序员站长】
大家好,又见面了,我是你们的朋友全栈君。
new TypeReference用法 fastjson
个人觉得涉及到的场景还是比较多的,多数我都用在调别人接口获取到的一些信息,然后映射实体的情况。 不知道这个方法的时候每次拿到一个字符串想去映射对象的时候,就jsonobject各种转换,转的自己都不想看自己写的代码,废话不多说上代码!!!
//这个new typeReference导入的包是package com.alibaba.fastjson;
//它还有一个包是package com.fasterxml.jackson.core.type;
/** *这是转成list的例子,转成对象还是map大体上差不多 **/
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());
}/** *转成对象 **/
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());
}发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/151110.html原文链接:https://javaforall.cn
边栏推荐
- conda 修改镜像源
- 揭秘GES超大规模图计算引擎HyG:图切分
- 一些常用的知识点积累
- RuntimeError: Trying to backward through the graph a second time (or directly access saved variable
- CONDA modifying a mirror source
- Precautions for using Jerry's timer [chapter]
- 【日常记录】——对BigDecimal除法运算时遇到的Bug
- Precautions for use of Jerry's SPI slave [chapter]
- Agent white paper - jointly build agents and create the wisdom of the whole scene | cloud library No.21 recommendation
- Hover effect of eight buttons
猜你喜欢

Garbage collector and memory allocation strategy
![[compilation principle] overview](/img/af/246750beb72842e83a19e42270c09e.png)
[compilation principle] overview

How to solve the problem of network disconnection after enabling hotspot sharing in win10?

什么是算子?
沁恒CH583 USB 自定义HID调试记录

Mobile heterogeneous computing technology - GPU OpenCL programming (basic)

ASP.NET超市便利店在线购物商城源码,针对周边配送系统

HMS core machine learning service realizes simultaneous interpretation, supports Chinese-English translation and multiple voice broadcast

CentOS7 安装 Redis 7.0.2

20 provinces and cities announce the road map of the meta universe
随机推荐
Essential characteristics of convolution operation +textcnn text classification
Computing architecture of microblog comments
图标丢失,URL附带JESSSIONID的什么来的?
十大证券公司哪个佣金最低 办理开户安全吗
RuntimeError: Trying to backward through the graph a second time (or directly access saved variable
股票开户怎么办理 办理开户安全吗
lock
为什么在变频器场合需要安科瑞的电力有源滤波器?
Getting started with kotlin (20) several common dialog boxes
力扣每日一题-第27天-561.数组拆分Ⅰ
[matlab] numerical calculus and equation solving
Unity technical manual - interference / noise sub module
【工作小技巧】刚入职的软件测试工程师怎么快速上手新岗位
SDN系统方法 | 10. SDN的未来
使用DiskGenius拓展系统盘C盘的容量
QT using SQLite database
Precautions for using Jerry's timer [chapter]
[compilation principle] lexical analysis
【 NLP 】 in this year's English college entrance examination, CMU delivered 134 high scores with reconstruction pre training, significantly surpassing gpt3
实际开户复杂吗?在线开户安全么?