JSONArray转javaList对象,下划线字母转小驼峰方法

原创
2024/08/05 17:13
阅读数 55
JSONArray转javaList对象,下划线字母转小驼峰方法
方法一:利用Gson的setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES)
List<EduCurrencyRateHistory> saveRateList = new ArrayList<>();
// 使用Gson进行转换
Gson gson = new GsonBuilder()
        .setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES)
        .create();
list.forEach(item -> {
    EduCurrencyRateHistory eduCurrencyRateHistory = gson.fromJson(item.toString(), EduCurrencyRateHistory.class);
    saveRateList.add(eduCurrencyRateHistory);
});
方法二:JSONReader.Feature.SupportSmartMatch
List<EduCurrencyRateHistory> saveList = list.toJavaList(EduCurrencyRateHistory.class, JSONReader.Feature.SupportSmartMatch);
展开阅读全文
加载中
点击引领话题📣 发布并加入讨论🔥
0 评论
0 收藏
0
分享
返回顶部
顶部