alibabaFastJson之json转指定List
发表于|更新于
|浏览量:
有一种健忘是高贵的,就是不记旧恶。——赛蒙兹
之前写了篇fastjson基本使用,这两天遇到一个意料之外的
需要把一个json的数组对象,转换成指定的List<User>
转换方式很简单
{“code”:200,”userList”:[{“password”:”achao”,”username”:”ruben”}],”data”:”操作成功!”,”list”:[“你好”,”加油”],”success”:true}
1 | JSONObject jsonObject = JSON.parseObject(jsonString); |
打印结果

相关推荐
2024-05-28
lombok的ExtensionMethod
短暂的分离可振奋情意,但长久的离别可毁灭情爱。——米拉波 @ExtensionMethod 今天玩了玩,还挺不错: 例如 12345678910111213141516171819202122232425import lombok.experimental.ExtensionMethod;@ExtensionMethod({java.util.Arrays.class, Extensions.class})public class ExtensionMethodExample { public String test() { int[] intArray = {5, 3, 8, 2}; intArray.sort(); String iAmNull = null; return iAmNull.or("hELlO, WORlD!".toTitleCase()); }}class Extensions { public static...
2024-06-24
MybatisPlus自动填充忽略存在值直接填充
再也无需前思后想,一切岂非已然过往。——《且听风吟》 代码如下,主要是重写strictFillStrategy方法 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576import cn.dev33.satoken.stp.StpUtil;import cn.hutool.core.lang.Opt;import com.baomidou.mybatisplus.core.MybatisConfiguration;import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;import com.baomidou.mybatisplus.core.handlers.StrictFill;import com.baomidou.mybatisplus.extension.plugin...
2022-07-13
泛型限定问题
双木非林,田下有心。——顾城 首先看这段代码: 12345678910111213141516171819202122import java.util.function.Function;class Scratch { static class RoleInfo { } public static void main(String[] args) { // 想让这两个通过 test(Object::hashCode, RoleInfo::hashCode, new RoleInfo()); test(Object::toString, RoleInfo::toString, new RoleInfo()); // 想让这个报错 test(Object::hashCode, RoleInfo::toString, new RoleInfo()); } public static <T, A, R> void te...
2023-01-01
lunar
人,现在最年轻啦。因为比起明天来,今天是年轻的。对于一个人来说,什么时候都是现在最年轻。──永六辅 lunar是一个支持阳历、阴历、佛历和道历的日历工具库,它开源免费,有多种开发语言的版本,不依赖第三方,支持阳历、阴历、佛历、道历、儒略日的相互转换,它能用来制作日历,甚至算命。 除此之外,还支持星座、干支、生肖、节气、节日、彭祖百忌、每日宜忌、吉神宜趋、凶煞宜忌、吉神方位、冲煞、纳音、星宿、八字、五行、十神、建除十二值星、青龙名堂等十二神、黄道日及吉凶等。 支持的时间跨度约为0001年至9999年。 地址:https://6tail.cn/calendar/api.html github: javascript:https://github.com/6tail/lunar-javascript java:https://github.com/6tail/lunar-java c#.net:https://github.com/6tail/lunar-csharp php(composer):https://github.com/6tail/lunar-php ph...
2022-11-19
CompletableFuture在超时后,能够停止执行吗?
沉默可能产生误解,我需要说话,说话将我推向歧途,我必须沉默。赫塔·米勒——《国王鞠躬,国王杀人》 好问题,尝试一下 123456789101112import java.util.concurrent.CompletableFuture;import java.util.concurrent.ExecutionException;import java.util.concurrent.TimeUnit;import java.util.concurrent.TimeoutException;import java.util.stream.Stream;class Scratch { public static void main(String[] args) throws ExecutionException, InterruptedException, TimeoutException { CompletableFuture.runAsync(() -> Stream.generate(Object::new).forEach(...
2021-05-31
flatMap
君子成人之美,不成人之恶。小人反是。——《论语》 在Stream中有这么一个函数 它和map不一样的是,map你输入多少个,输出就是多少个 例如我要生成一个集合,装着26个小写字母和26个大写字母 用flatMap可以一行实现 12List<String> abc = Stream.iterate('a', i -> ++i).map(String::valueOf).limit(26).flatMap(i -> Stream.concat(Stream.of(i), Stream.of(i).map(String::toUpperCase))).sorted().collect(Collectors.toList());System.out.println(abc); 马上这时候就有人跳出来说,我不用flatMap还不是可以!!!不信你看 12List<Character> ab = Stream.iterate('A', i -> ++i).limit(58).filter(i -&g...
