转换地图<字符串,字符串>到 POJO [英] Convert a Map<String, String> to a POJO

查看:44
本文介绍了转换地图<字符串,字符串>到 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 来实现.(而且由于您考虑使用杰克逊,它似乎更舒服).

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

使用 ObjectMapperconvertValue 方法:

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.

这篇关于转换地图<字符串,字符串>到 POJO的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆