当前位置:网站首页>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
边栏推荐
- Distributed remote management of distribution room environment
- Precautions for using Jerry's timer [chapter]
- 什么是算子?
- Use of jupyter
- [matlab] data interpolation
- Computing architecture of microblog comments
- User scheduling problem
- Deeply understand and grasp the basic characteristics of digital economy
- Under the same WiFi, the notebook is connected to the virtual machine on the desktop
- Jerry's addition of encrypted file playback function [chapter]
猜你喜欢

SQL Server实时备份库要求
![Jericho's method of obtaining reset source and wakeup IO port [chapter]](/img/93/30d5075a3da1ace7438ae06c1b1775.png)
Jericho's method of obtaining reset source and wakeup IO port [chapter]

SDN系统方法 | 10. SDN的未来

New characteristics of cultural consumption in the era of digital economy

How to judge whether you are suitable for software testing

【 NLP 】 in this year's English college entrance examination, CMU delivered 134 high scores with reconstruction pre training, significantly surpassing gpt3

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

揭秘GES超大规模图计算引擎HyG:图切分

观察者模式之通用消息发布与订阅

什么是算子?
随机推荐
Use diskgenius to expand the capacity of system disk C
Swagger实现后台接口自动化文档
Video production material website arrangement
golang sort slice int
【工作小技巧】刚入职的软件测试工程师怎么快速上手新岗位
conda安装的py3.6和py3.7
TLV解码
Time series analysis of data mining [easy to understand]
Three traversal methods of binary tree (recursive + non recursive) complete code
Vscode automatically generates ifndef define ENDIF of header file
Deep understanding of ELF files
实际开户复杂吗?在线开户安全么?
使用DiskGenius拓展系統盤C盤的容量
How to judge whether you are suitable for software testing
Agent white paper - jointly build agents and create the wisdom of the whole scene | cloud library No.21 recommendation
Computing architecture of microblog comments
Which of the top ten securities companies has the lowest commission? Is it safe to open an account
Can I open an account? Is it safe to open an account
mysql mysql-8.0.19-winx64 安装与navicat连接
什么是算子?