转换 Map<String, String>到 POJO

编程入门 行业动态 更新时间:2024-10-10 23:15:48
本文介绍了转换 Map&lt;String, String>到 POJO的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我一直在看 Jackson,但似乎我必须将 Map 转换为 JSON,然后将生成的 JSON 转换为 POJO.

I've been looking at Jackson, but is seems I would have to convert the Map to JSON, and then the resulting JSON to the POJO.

有没有办法将 Map 直接转换为 POJO?

Is there a way to convert a Map directly to a POJO?

推荐答案

好吧,您也可以通过 Jackson 实现这一目标.(而且因为您考虑使用 jackson 似乎更舒服).

Well, you can achieve that with Jackson, too. (and it seems to be more comfortable since you were considering using jackson).

使用 ObjectMapper 的 convertValue 方法:

Use ObjectMapper's convertValue method:

final ObjectMapper mapper = new ObjectMapper(); // jackson's objectmapper final MyPojo pojo = mapper.convertValue(map, MyPojo.class);

无需转换成JSON字符串或其他东西;直接转换的速度要快得多.

No need to convert into JSON string or something else; direct conversion does much faster.

更多推荐

转换 Map<String, String>到 POJO

本文发布于:2023-11-25 10:25:38,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1629387.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:lt   Map   String   POJO   gt

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!